From nobody Tue Nov 26 15:33:41 2024 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 0D4F61CF7C7 for ; Thu, 17 Oct 2024 08:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152872; cv=none; b=l2IGGn2JXxENko5SEGu6JUvrNT0UN9nJ2/WdFCrcuorPeGj4MukQuzjbORj+9I5JuX+uhywGsQZtXysAmm9jCQHsz7kvxo9y14I6QhlPdgzbZBEVTcU+PuynO08DHrAOHIajKCspP8xXw9bs7fYQFzPRO7QM8Grq1qNY16myarg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152872; c=relaxed/simple; bh=POHh8g+2CvyZoU0L+E1KmaYOw5grZB9aKoaGo7YEz6Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ipOLH5U3VqrELyWFLOoyiWTwcilZWF70eLyCLX4BaH28jr2uJ8+OlCwXqmVwKjj7K2Tz9lWAXo+xJfNYzFTy8pWZMAjEkpPzK3McvGvZ8NwzM+Fl1zc8flu2nk6RHIcVx7bQ70gDSR0Wgs6dkOOBzgUHFgrvnl9czFkio3P5JrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=TxxGpTwx; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="TxxGpTwx" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-539f84907caso824964e87.3 for ; Thu, 17 Oct 2024 01:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152864; x=1729757664; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OB/wBkvSEUCyn6Pce3Sw/d9S+YTAmxmeVBF6YPbGUIs=; b=TxxGpTwxES3o/RKFvyDwnAMwVyIgnpZSed7J8NEJ/2+KBPx3rxk78RFPvly6bPPPe1 sqIk15Tq8ARXGtSEqR2RiKHUYrrF2SeP1XfPdw8lIan3oVEKTbD7VqjrlV/mVv9G7aCb fugp19M8vdz27uQGm+YHSDHGTVekkqonePHdQJJ6qBPGVwlWHRDSUZT5r0MQKNxfUASe EcJPBezCjjUIMm5b9QgmEXWW7EXxydKIzFzL3yhT7r4QBOFv7gpe+S6cW+Zo4AzJgmVW fBozIrlhvdtIk4s0Jw0BOxyDpQgQ7Mdco0j37KYeWGR3XXV0RzVjDWelpy0KMlK0yk2c U/Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152864; x=1729757664; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OB/wBkvSEUCyn6Pce3Sw/d9S+YTAmxmeVBF6YPbGUIs=; b=F/PvxS+t8+ivmiMZOZcRH0uHVvlEUc8ZwUrxwZyLmPctjzMBYJ79YQsSHdY0EEnCur PBMRlt9Sp3maPKdmi+RavHpzFlhD30yAtxs+cq4ZQDsBc4KnOCUDVmL5KqBHY2vNvDd1 h50GmXWtMdxwsLexI+oCck1DHiQi7gCokq091mcpG7Z4Qgz8xtLDMoFQiQvEljUzNP5i YIHhf7dARGFKkMQSSzmeYCgE8jAgjt5mQ0rMVPPVKvuak20L57BAZb3hHqNmnft/NqVd 1bpSgPlGJ58kS/tOkFzDHZi2VVpMatHuroMP6gvc8OSlBNz/0RrhyVV8Nkmp9AyyE7hp dMMA== X-Forwarded-Encrypted: i=1; AJvYcCWMXR3EwIf7f+3R9yxm29jMOJVn6GyleulKMtDT3unV1YuKlnIHi0Fa8pKgzDgrrP1Caj7DNtZNsJSHFEg=@vger.kernel.org X-Gm-Message-State: AOJu0YyQ+eRKwkkMSMhwqpuOEnGbsZFVHgy1mQLaW9WQx4uIsMRAXvyq zgSNIxBhGHYxHVAA4VXPO5IC0awAoo0Vq1MnAOX/s9pVY6opYbRJXQEsQqIxIEs= X-Google-Smtp-Source: AGHT+IFRnHFVacQn63nVwfrSGciFYzsNocWAWHtg4UziLMgw64RaHnmxTESwoE68vQdpohDATLOkvw== X-Received: by 2002:a05:6512:ea0:b0:539:f471:bcfa with SMTP id 2adb3069b0e04-53a03f18296mr4890823e87.14.1729152864395; Thu, 17 Oct 2024 01:14:24 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:24 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:09 +0200 Subject: [PATCH v4 1/8] gpiolib: notify user-space when a driver requests its own desc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-1-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=782; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=zMsMSJX1Nl0+caHE+JZSEzX7KhbE4YG1tQGrQmi8r44=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMdcHXhTx0y5m8JPij1Ef1Zc5QZ1ycidlcQUc uaji8i8gw+JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXAAKCRARpy6gFHHX cjAaD/9yKJH6txh1M0Oi2hTCivfnX3YO/dSu5lRS6NPhWUNYQ4V5h76Ns8k1wDh1FvKOHTlJsNA xrBqiIiFSfXdIf97ceyyAVcRKPR8vCF8O0chLadgqDA5cSo+A8JN8GfxLFQn+dUnBJYdYBE8Ehg dZ+Kf+lFAAGRutsrDWQrMrWbU7Ww1VYsAHL/K90Mbu/KCwMfQeJ8Gg9hvWX/vjaIAG6kaAUkM6c trHoGhz6X5GvoxIHKaH6tjJMvljez3/1cKVBu52Me2yGGirgYKG+wDKZVmRawRjMxwAMBht+MD7 gyRZBKZOacWI2hyO6h4ExRkPEMeSuV1Krbjh5w7AFnnMV0z4LraN/eIoXFIUUceTlTaYibi9cDn vxJ80ysO79/jbXUYYzdcUkYTZPyV32+zt0kP70m4jxf9PxAj/8rTN3tyH989qXNLBSELjGosILQ 67bZsa/y2oNE5hxbLDAjp/ig+9hETn1gFZiNa5bLn+pjgFjrcW+hEAhT8WuNbjkAxOqmUvKJkwA gk5jorR6IWr9hoQhE1iGDQ7+cpTKAZ/xu4ZTnpVsKG7AhYcOIC/8W459XD7PoP9EH+1KAqzNQkX Poy39h3m3noDJFx5GwjYBg92KuD8hYpnT7UbODhVPNg+s5GFcTQzvUrsJpwf0oYcM4AswcYdRCa TGMw9nDmyscoFfA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We notify user-space about lines being requested from user-space or by drivers calling gpiod_get() but not when drivers request their own lines so add the missing call to gpiod_line_state_notify(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 97346b746ef5..c09464f70f73 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2532,6 +2532,8 @@ struct gpio_desc *gpiochip_request_own_desc(struct gp= io_chip *gc, return ERR_PTR(ret); } =20 + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); + return desc; } EXPORT_SYMBOL_GPL(gpiochip_request_own_desc); --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 118C41D26E8 for ; Thu, 17 Oct 2024 08:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152868; cv=none; b=toJPK9OCLc5biLZZsZq7+tGpLa3MmPjVRs9xTavas9o780jlR1BYJ9vsbxjcQ9yexUwlQ0ATH2MYX/DPPaeXQC7qLvYZ5XsQE9XA/a4lV/h6tJ1fK24Aw95XM4riqQrQ30iohNkGIVM69CsOUg9TuusRHXOUFyM/TJ614rn6EBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152868; c=relaxed/simple; bh=ND47jIbOYDmJs8MpSoNGSSJKSen6G5z88AQQSxF1llA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lwBCRgljUjEKlp/ca5K9J0b5eNNvd89Rl24bEer9CX3XtF0FF8B6E4cKS74TCltgivrc5DyZSMdJff3EpDAh8qrKryKwRDskRFcPye1gMl9x7Xczwarpl0KdadB6HLxs483puMZ7BWyqm2fjwC4Y4sfbM/5UrO9Wzvw4c52GnlI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=hswZcMdZ; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="hswZcMdZ" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43159c9f617so4334915e9.2 for ; Thu, 17 Oct 2024 01:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152865; x=1729757665; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sLpytUujQtrQRxKwGItE9MBF3PBkf2ocRMe5UxADIfc=; b=hswZcMdZDg6hFDe6alxWVTtCmypqu68euJ+95ao7Rz+pRYOgIbkKmiF/w4+3cb11Z+ 78vbBHe7s5/9BK8rDrtXUk21UVSlNrT7jT4TBi3ng8DWPw6huE/fBM8ilwiwTIbUfJ66 j42rkwXra2k9U73tya8IqMnj1DwYl6FX7IhePwZFF4NZjIjvRRT8FJRNGYKKAXuk0Km7 2iWB73yA4zlt89BcuKsK+mESOrUBmSfPBZmcfQgwsZdxUycDcBIMX4mcE2frH+LjgQQ8 KNwbCZvwyIqh2C7mzDNRsw/T0E/03U8tK+bVTd9V9y/k54HlR5GW1ssG1DOHbbMeQKk3 1EHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152865; x=1729757665; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sLpytUujQtrQRxKwGItE9MBF3PBkf2ocRMe5UxADIfc=; b=l67/xiFfp+BTa1SUCRDYildg8N3A0WU072hqw5E9fVT1G+5YIWePRLtOT9fHue0W2z AvDm88G4Q9Xx22ftKYSwJQQloZQ6yprtcFlaAzksMjJZi8Navd5oPWaj5P2nDwybn0F3 5pUkodOWwroGa+YlVFDW+LpWEcNFOIbuHGWSGwuo7haLlciJgv3IXfXw8a7WdE5rot6q KYo7sngxBHJEKXOM23Q7upFR69PyJclZmf/sYTG4FFTKfZvABhCRaoRM/qiSJ9xjTSR/ xC2PMdbdgbKkuQKhJStGLjhSMeuZ2C2YfT9b0J9kTBtv1xMYBzs95TAfcY3v+FTR9WiH zXUw== X-Forwarded-Encrypted: i=1; AJvYcCUNQeb/+TnAxx9vJ+EYtHzblCpcEctFnrtFjtUhKW/sfZpMx9tHZMxLw0XaQetluKf91un4r/xkqBdbyY0=@vger.kernel.org X-Gm-Message-State: AOJu0YzgA+pjOQqYZgtX02E0T4azsxSjYaDxi+BYeMVFhveSTTHMMEL4 szm9ICUldjQmM9sOkvyE+7GB1qEtoBDNO0EZYSyXjtfxuEOsL8VWMZPIUPl+I4aA2fl84zeo54b 4 X-Google-Smtp-Source: AGHT+IHzF2qT2sTor36rFrvkN3Jdnog6ETuCHp5zH8opv/EtydEdzHVKUwFbUeojf/ZStUGQnKNYmg== X-Received: by 2002:a05:600c:314f:b0:431:52c4:1069 with SMTP id 5b1f17b1804b1-43152c412eamr36318205e9.8.1729152865107; Thu, 17 Oct 2024 01:14:25 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:24 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:10 +0200 Subject: [PATCH v4 2/8] gpiolib: unduplicate chip guard in set_config path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-2-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2395; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=5bkoQOmE+e79NCUZkE2hkqB3kJJTpG+Rd7AZwxRE2E4=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMdcC3OI1Ir1Rau9V0RSZUWiGg3TGO6oiTtTw F6cv6JTpD+JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXAAKCRARpy6gFHHX cjU+EACP3LgjIItD0S2u03ccGO+2y1ZSqg0lUrZM8TUzO903niSMQUprfHC6Jx8nrNXMnLPSA4J JwJIrEBTfgzgohscQGfcDX3N6PBccujjHsScvu1L8oA1SNDzXj5vomZ1PKiQU+mm86h0k36EfRQ eQjQBSVxoCKQAVuOYnaiaugxv6dIA3DaHZYnO+1XgTH0Hlyn8GcWhh6t4SZ3k3EbUyhNnpNNiBj zJuAm7eyRm1/hSDrXoEF+jhJK5tgEb54n2Ev/eDolo6xClytxATDy/d9HiBt/cA+fa3Ih7/vq8+ UKaJSEhqrkEckWS16uzwPDWx9b/y786y2a0lvGwMcSxXxWzdS1eU+2LBPQmhDAW7FqW0+6AzfKU h2mlFiOlAzYEkyFNe/hdJR5cFOfzV435FDH0q3jZxQ6fMyL5/cuDh8Q73Xw/toVvVnt0pUGRVaL QZx65x/kJgje9LKVa9YTn5iMWB6tKYKT2SOGdaAgu6g4UUNbGLqxvxR2N473U/ieg74CYCzNs1b fieV78I4ek9ic4e6Qi+gC07CZGd12EfaQUFloxbphdmN9+MoiTfoZCDmijZhTkYzTMYJx4jHcuy UZaI5nAhcuEB2PY4MGbK4p0sqfSXKYmR0MxF2ZgWSnejtiEaVQhpPnyGpSIpOADGW+UwH0eAwV6 b/iqhtolvtslxQw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We don't need to guard the GPIO chip until its first dereference in gpio_do_set_config(). First: change the prototype of gpio_do_set_config() to take the GPIO line descriptor as argument, then move the gpio_chip protection into it and drop it in two places where it's done too early. This has the added benefit of making gpio_go_set_config() safe to use from outside of this compilation unit without taking the gdev SRCU read lock and will come in handy when we'll want to make it available to the character device code. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c09464f70f73..b1ce213d3a23 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2562,13 +2562,16 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); * rely on gpio_request() having been called beforehand. */ =20 -static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset, - unsigned long config) +static int gpio_do_set_config(struct gpio_desc *desc, unsigned long config) { - if (!gc->set_config) + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + + if (!guard.gc->set_config) return -ENOTSUPP; =20 - return gc->set_config(gc, offset, config); + return guard.gc->set_config(guard.gc, gpio_chip_hwgpio(desc), config); } =20 static int gpio_set_config_with_argument(struct gpio_desc *desc, @@ -2577,12 +2580,8 @@ static int gpio_set_config_with_argument(struct gpio= _desc *desc, { unsigned long config; =20 - CLASS(gpio_chip_guard, guard)(desc); - if (!guard.gc) - return -ENODEV; - config =3D pinconf_to_config_packed(mode, argument); - return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); + return gpio_do_set_config(desc, config); } =20 static int gpio_set_config_with_argument_optional(struct gpio_desc *desc, @@ -2944,11 +2943,7 @@ int gpiod_set_config(struct gpio_desc *desc, unsigne= d long config) { VALIDATE_DESC(desc); =20 - CLASS(gpio_chip_guard, guard)(desc); - if (!guard.gc) - return -ENODEV; - - return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); + return gpio_do_set_config(desc, config); } EXPORT_SYMBOL_GPL(gpiod_set_config); =20 --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 EFA561D27BE for ; Thu, 17 Oct 2024 08:14:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152871; cv=none; b=Sls6Ho1wh1mftCVZWe8ITStK8LB7uVg2ilkZ417n38FHhrLMO1u8ChkhO707DxNbqn4qyVOesH7xBhp4ivR+p6mq0elZ+yiSN7j4J5Totkc++DUjsI5IOkG9jKLgiXskWulpNjfa+GB3o8hcJ7vm8ZU6hHl1ssb0O80I3rNspGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152871; c=relaxed/simple; bh=Y6ydoHY2HpsK8/L2hWNEthXCW5yOTtkkUFG5ZyOBLHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dZgBcBeoJpIokLA/1q5B1YbtDsky3r/a/tddIO60tnGvU8kz5s311ZSH+e0Degy6p5GXozkYoCWYJIGlu2uap1qMrzQ11TD7v7hWglptghST++Jr3Qnw2R07xhksjxYPTaC0Txy6NtCGR09U5Ra56FejQ1NerUnLmqtnvyVsX4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=oVGZizqc; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="oVGZizqc" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-37d4d1b48f3so469736f8f.1 for ; Thu, 17 Oct 2024 01:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152867; x=1729757667; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lNIOspkDRS2AyiERRhXLD4LKdJKYWTfCk5EQAGqlBPE=; b=oVGZizqcMvhNFuR8H+vxWgItECEt8lFof9lD655kNGA0lFurz6GLlUScRfYHzDUX/K BQOiznU4cmpd9nx2EzydciBaWAPOeLGZF/+Ri5CUkum8xBma+cLCEWTH8UsyrJbHzWkQ mGu/0IoGwxPpDTpubpOhaQ04WonX9Yy/Ut8+ePT9MKdT5IpE5Tx3Dth6Mu8Uo7thjn34 nKl3YOJwAE4bW2/D8bIliP+D3cswmKnIsL+oWCfP8fDZgGCuWavobdGr7h4BlY5hDk+p qi39Pg8OUDJldQ+CYaV+XN3hNzgvRzAoD4PtE/8scRAQTp63QUj5g/WvRcqyu3rrRczM 0knQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152867; x=1729757667; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lNIOspkDRS2AyiERRhXLD4LKdJKYWTfCk5EQAGqlBPE=; b=rz6EdGuz98OGqKDa7rJzzoh8BlKbvZG6LQ5IVAeeSTjjOybD3m+C1FSkcq7Zpgc6Mi E+KL3wT8Ex2VBZuef2RbTsEBq/PRZjzaliGzpEijz2GCojFTv+50ABhWIgDs/E2CmfO4 Ac97bZ0upD94s4he1obj2Z8Zy16T9wJUCRvwN0TwYDs4rUXfXa2CwkZPmBtnmRK21zTB MUk6qR+LuCIz7dNoDLVobd93Z6+UMNzuVAuTwZceoJTROWlOofxCJbhcV9zKQppKW5f4 lPy1ljHyXOzPtmSL2Yk8PCiAeqDsCDaKxiVrpq22wLZc7pLoMOdmIs8ZZWnaH7+uUU56 nJGw== X-Forwarded-Encrypted: i=1; AJvYcCWGIEUVVzb8xs6TP+sD+nizPDj9j327QtL5U4i1ROuq2GvRc1cESokl/HaXUL8l4XUCyuOxPjDmE8LR8fg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6p/OyortghRSR38P2R4c8+60Ief+1NlGzotW6cnmNd3iJcQaq SYjdU7e5NHezebOYcTOjfdpZU/Ayp4U+b6Xz7Nsr2iPSHsaZm3Zvc1sIGlY1vlE= X-Google-Smtp-Source: AGHT+IGKMPPopBXB9GhVXxjvwJjItMobARzH/XoVpj9q9lAkKZYlkf9r8FM1HiK3YV1xwZQfGSZ5hQ== X-Received: by 2002:a5d:568b:0:b0:374:b6f3:728d with SMTP id ffacd0b85a97d-37d55262d47mr14631834f8f.46.1729152866922; Thu, 17 Oct 2024 01:14:26 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:25 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:11 +0200 Subject: [PATCH v4 3/8] gpio: cdev: go back to storing debounce period in the GPIO descriptor Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-3-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=13582; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=KMwpLTqbSzLk7Bonso7QQ+aG3uhStA029vtPSa2jEoU=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMdcUCX63EqaIQF3Z3mJ2qQ2vpwPcLZytM4yg Zq4Y+3QCMGJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXAAKCRARpy6gFHHX crZ9EACU9+UlQirlcChF/kdVJMRhR4PDrxEGPOfJEZWLIdZc8TMu4RtbphFZWPOQGhhIuMUo0aZ 2S78hiEN4ZthdjueBUB/IAcFQ/K488WzSsFvOlpKNr9N3soolGRIRtbbxyNYLgiD8xobIIZ0zZM 2nqU75vS3DjO440Fn2JWJzgTp9qBHFk0cE1cknH9+C+yWyv3mnMnLKJ3Fycxa+mCIzgT3oOAIlt YN+IJak0Dem8ghjWkHcc8mR3K4T8WgO+35P5ah+AWa75ikGmod4Ozz07xnmwedV+IQz1yeywgfU gWDYnVV4QGWsPrGIYRdXQwwH3NKntqWr59q9ks5RZ6j3xJU1+NHSacT1Psicn29AAWqBIi9aFLc z3c644Sj1LVnpMGBT5FjaGQfxZONw2FZsXAIuv5ZxwI/e+P8i62ezTb33aTbgY1MmQYDf9ywH8L lyIfiL3qO+L5bT5jg6zGW44THYh9solO0Nl8olDB430uMdEphG/V6MSsp3Z9oU/680D+mEnrddx dvpse1gTsx4RD7p6us5wlW3e396DKIX6IfjysUNRz47yX53cbb+RcGvrM68WKRyvzZDv4UYP8LT J6wm31RQf82tt8vFlXe9IUulaQ6Me+R75HqMbHxFXzFiYl5PhdNXthc3IHxszYXPPlJMtPkf3kh NeuP6oFOJ6ZJI8Q== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski This effectively reverts commits 9344e34e7992 ("gpiolib: cdev: relocate debounce_period_us from struct gpio_desc") and d8543cbaf979 ("gpiolib: remove debounce_period_us from struct gpio_desc") and goes back to storing the debounce period in microseconds in the GPIO descriptor We're doing it in preparation for notifying the user-space about in-kernel line config changes. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 163 ++++++----------------------------------= ---- drivers/gpio/gpiolib.c | 18 ++++- drivers/gpio/gpiolib.h | 5 ++ 3 files changed, 43 insertions(+), 143 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index b0050250ac3a..d55d2a246d41 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -421,7 +420,6 @@ static int linehandle_create(struct gpio_device *gdev, = void __user *ip) =20 /** * struct line - contains the state of a requested line - * @node: to store the object in supinfo_tree if supplemental * @desc: the GPIO descriptor for this line. * @req: the corresponding line request * @irq: the interrupt triggered in response to events on this GPIO @@ -434,7 +432,6 @@ static int linehandle_create(struct gpio_device *gdev, = void __user *ip) * @line_seqno: the seqno for the current edge event in the sequence of * events for this line. * @work: the worker that implements software debouncing - * @debounce_period_us: the debounce period in microseconds * @sw_debounced: flag indicating if the software debouncer is active * @level: the current debounced physical level of the line * @hdesc: the Hardware Timestamp Engine (HTE) descriptor @@ -443,7 +440,6 @@ static int linehandle_create(struct gpio_device *gdev, = void __user *ip) * @last_seqno: the last sequence number before debounce period expires */ struct line { - struct rb_node node; struct gpio_desc *desc; /* * -- edge detector specific fields -- @@ -477,15 +473,6 @@ struct line { * -- debouncer specific fields -- */ struct delayed_work work; - /* - * debounce_period_us is accessed by debounce_irq_handler() and - * process_hw_ts() which are disabled when modified by - * debounce_setup(), edge_detector_setup() or edge_detector_stop() - * or can live with a stale version when updated by - * edge_detector_update(). - * The modifying functions are themselves mutually exclusive. - */ - unsigned int debounce_period_us; /* * sw_debounce is accessed by linereq_set_config(), which is the * only setter, and linereq_get_values(), which can live with a @@ -518,17 +505,6 @@ struct line { #endif /* CONFIG_HTE */ }; =20 -/* - * a rbtree of the struct lines containing supplemental info. - * Used to populate gpio_v2_line_info with cdev specific fields not contai= ned - * in the struct gpio_desc. - * A line is determined to contain supplemental information by - * line_has_supinfo(). - */ -static struct rb_root supinfo_tree =3D RB_ROOT; -/* covers supinfo_tree */ -static DEFINE_SPINLOCK(supinfo_lock); - /** * struct linereq - contains the state of a userspace line request * @gdev: the GPIO device the line request pertains to @@ -542,8 +518,7 @@ static DEFINE_SPINLOCK(supinfo_lock); * this line request. Note that this is not used when @num_lines is 1, as * the line_seqno is then the same and is cheaper to calculate. * @config_mutex: mutex for serializing ioctl() calls to ensure consistency - * of configuration, particularly multi-step accesses to desc flags and - * changes to supinfo status. + * of configuration, particularly multi-step accesses to desc flags. * @lines: the lines held by this line request, with @num_lines elements. */ struct linereq { @@ -559,103 +534,6 @@ struct linereq { struct line lines[] __counted_by(num_lines); }; =20 -static void supinfo_insert(struct line *line) -{ - struct rb_node **new =3D &(supinfo_tree.rb_node), *parent =3D NULL; - struct line *entry; - - guard(spinlock)(&supinfo_lock); - - while (*new) { - entry =3D container_of(*new, struct line, node); - - parent =3D *new; - if (line->desc < entry->desc) { - new =3D &((*new)->rb_left); - } else if (line->desc > entry->desc) { - new =3D &((*new)->rb_right); - } else { - /* this should never happen */ - WARN(1, "duplicate line inserted"); - return; - } - } - - rb_link_node(&line->node, parent, new); - rb_insert_color(&line->node, &supinfo_tree); -} - -static void supinfo_erase(struct line *line) -{ - guard(spinlock)(&supinfo_lock); - - rb_erase(&line->node, &supinfo_tree); -} - -static struct line *supinfo_find(struct gpio_desc *desc) -{ - struct rb_node *node =3D supinfo_tree.rb_node; - struct line *line; - - while (node) { - line =3D container_of(node, struct line, node); - if (desc < line->desc) - node =3D node->rb_left; - else if (desc > line->desc) - node =3D node->rb_right; - else - return line; - } - return NULL; -} - -static void supinfo_to_lineinfo(struct gpio_desc *desc, - struct gpio_v2_line_info *info) -{ - struct gpio_v2_line_attribute *attr; - struct line *line; - - guard(spinlock)(&supinfo_lock); - - line =3D supinfo_find(desc); - if (!line) - return; - - attr =3D &info->attrs[info->num_attrs]; - attr->id =3D GPIO_V2_LINE_ATTR_ID_DEBOUNCE; - attr->debounce_period_us =3D READ_ONCE(line->debounce_period_us); - info->num_attrs++; -} - -static inline bool line_has_supinfo(struct line *line) -{ - return READ_ONCE(line->debounce_period_us); -} - -/* - * Checks line_has_supinfo() before and after the change to avoid unnecess= ary - * supinfo_tree access. - * Called indirectly by linereq_create() or linereq_set_config() so line - * is already protected from concurrent changes. - */ -static void line_set_debounce_period(struct line *line, - unsigned int debounce_period_us) -{ - bool was_suppl =3D line_has_supinfo(line); - - WRITE_ONCE(line->debounce_period_us, debounce_period_us); - - /* if supinfo status is unchanged then we're done */ - if (line_has_supinfo(line) =3D=3D was_suppl) - return; - - /* supinfo status has changed, so update the tree */ - if (was_suppl) - supinfo_erase(line); - else - supinfo_insert(line); -} - #define GPIO_V2_LINE_BIAS_FLAGS \ (GPIO_V2_LINE_FLAG_BIAS_PULL_UP | \ GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN | \ @@ -823,7 +701,7 @@ static enum hte_return process_hw_ts(struct hte_ts_data= *ts, void *p) line->total_discard_seq++; line->last_seqno =3D ts->seq; mod_delayed_work(system_wq, &line->work, - usecs_to_jiffies(READ_ONCE(line->debounce_period_us))); + usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); } else { if (unlikely(ts->seq < line->line_seqno)) return HTE_CB_HANDLED; @@ -964,7 +842,7 @@ static irqreturn_t debounce_irq_handler(int irq, void *= p) struct line *line =3D p; =20 mod_delayed_work(system_wq, &line->work, - usecs_to_jiffies(READ_ONCE(line->debounce_period_us))); + usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); =20 return IRQ_HANDLED; } @@ -1047,7 +925,7 @@ static int debounce_setup(struct line *line, unsigned = int debounce_period_us) /* try hardware */ ret =3D gpiod_set_debounce(line->desc, debounce_period_us); if (!ret) { - line_set_debounce_period(line, debounce_period_us); + WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); return ret; } if (ret !=3D -ENOTSUPP) @@ -1132,7 +1010,8 @@ static void edge_detector_stop(struct line *line) cancel_delayed_work_sync(&line->work); WRITE_ONCE(line->sw_debounced, 0); WRITE_ONCE(line->edflags, 0); - line_set_debounce_period(line, 0); + if (line->desc) + WRITE_ONCE(line->desc->debounce_period_us, 0); /* do not change line->level - see comment in debounced_value() */ } =20 @@ -1165,7 +1044,7 @@ static int edge_detector_setup(struct line *line, ret =3D debounce_setup(line, debounce_period_us); if (ret) return ret; - line_set_debounce_period(line, debounce_period_us); + WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); } =20 /* detection disabled or sw debouncer will provide edge detection */ @@ -1213,12 +1092,12 @@ static int edge_detector_update(struct line *line, gpio_v2_line_config_debounce_period(lc, line_idx); =20 if ((active_edflags =3D=3D edflags) && - (READ_ONCE(line->debounce_period_us) =3D=3D debounce_period_us)) + (READ_ONCE(line->desc->debounce_period_us) =3D=3D debounce_period_us)) return 0; =20 /* sw debounced and still will be...*/ if (debounce_period_us && READ_ONCE(line->sw_debounced)) { - line_set_debounce_period(line, debounce_period_us); + WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); /* * ensure event fifo is initialised if edge detection * is now enabled. @@ -1677,7 +1556,6 @@ static ssize_t linereq_read(struct file *file, char _= _user *buf, =20 static void linereq_free(struct linereq *lr) { - struct line *line; unsigned int i; =20 if (lr->device_unregistered_nb.notifier_call) @@ -1685,14 +1563,10 @@ static void linereq_free(struct linereq *lr) &lr->device_unregistered_nb); =20 for (i =3D 0; i < lr->num_lines; i++) { - line =3D &lr->lines[i]; - if (!line->desc) - continue; - - edge_detector_stop(line); - if (line_has_supinfo(line)) - supinfo_erase(line); - gpiod_free(line->desc); + if (lr->lines[i].desc) { + edge_detector_stop(&lr->lines[i]); + gpiod_free(lr->lines[i].desc); + } } kfifo_free(&lr->events); kfree(lr->label); @@ -2363,6 +2237,7 @@ static void gpio_v2_line_info_changed_to_v1( static void gpio_desc_to_lineinfo(struct gpio_desc *desc, struct gpio_v2_line_info *info) { + u32 debounce_period_us; unsigned long dflags; const char *label; =20 @@ -2435,6 +2310,14 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *= desc, info->flags |=3D GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME; else if (test_bit(FLAG_EVENT_CLOCK_HTE, &dflags)) info->flags |=3D GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE; + + debounce_period_us =3D READ_ONCE(desc->debounce_period_us); + if (debounce_period_us) { + info->attrs[info->num_attrs].id =3D GPIO_V2_LINE_ATTR_ID_DEBOUNCE; + info->attrs[info->num_attrs].debounce_period_us =3D + debounce_period_us; + info->num_attrs++; + } } =20 struct gpio_chardev_data { @@ -2540,7 +2423,6 @@ static int lineinfo_get(struct gpio_chardev_data *cde= v, void __user *ip, return -EBUSY; } gpio_desc_to_lineinfo(desc, &lineinfo); - supinfo_to_lineinfo(desc, &lineinfo); =20 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) { if (watch) @@ -2633,7 +2515,6 @@ static int lineinfo_changed_notify(struct notifier_bl= ock *nb, chg.event_type =3D action; chg.timestamp_ns =3D ktime_get_ns(); gpio_desc_to_lineinfo(desc, &chg.info); - supinfo_to_lineinfo(desc, &chg.info); =20 ret =3D kfifo_in_spinlocked(&cdev->events, &chg, 1, &cdev->wait.lock); if (ret) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b1ce213d3a23..807bee86afd5 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2432,7 +2432,9 @@ static void gpiod_free_commit(struct gpio_desc *desc) #endif desc_set_label(desc, NULL); WRITE_ONCE(desc->flags, flags); - +#ifdef CONFIG_GPIO_CDEV + WRITE_ONCE(desc->debounce_period_us, 0); +#endif gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_RELEASED); } } @@ -2564,6 +2566,8 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); =20 static int gpio_do_set_config(struct gpio_desc *desc, unsigned long config) { + int ret; + CLASS(gpio_chip_guard, guard)(desc); if (!guard.gc) return -ENODEV; @@ -2571,7 +2575,17 @@ static int gpio_do_set_config(struct gpio_desc *desc= , unsigned long config) if (!guard.gc->set_config) return -ENOTSUPP; =20 - return guard.gc->set_config(guard.gc, gpio_chip_hwgpio(desc), config); + ret =3D guard.gc->set_config(guard.gc, gpio_chip_hwgpio(desc), config); +#ifdef CONFIG_GPIO_CDEV + /* + * Special case - if we're setting debounce period, we need to store + * it in the descriptor in case user-space wants to know it. + */ + if (!ret && pinconf_to_config_param(config) =3D=3D PIN_CONFIG_INPUT_DEBOU= NCE) + WRITE_ONCE(desc->debounce_period_us, + pinconf_to_config_argument(config)); +#endif + return ret; } =20 static int gpio_set_config_with_argument(struct gpio_desc *desc, diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 067197d61d57..8daba06eb472 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -165,6 +165,7 @@ struct gpio_desc_label { * @label: Name of the consumer * @name: Line name * @hog: Pointer to the device node that hogs this line (if any) + * @debounce_period_us: Debounce period in microseconds * * These are obtained using gpiod_get() and are preferable to the old * integer-based handles. @@ -202,6 +203,10 @@ struct gpio_desc { #ifdef CONFIG_OF_DYNAMIC struct device_node *hog; #endif +#ifdef CONFIG_GPIO_CDEV + /* debounce period in microseconds */ + unsigned int debounce_period_us; +#endif }; =20 #define gpiod_not_found(desc) (IS_ERR(desc) && PTR_ERR(desc) =3D=3D -ENOE= NT) --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 AF50F1D3185 for ; Thu, 17 Oct 2024 08:14:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152871; cv=none; b=HEgOElfxv6uXklo/ovAIiTSW45t1n2/ZhSSkNK7aIz86quc1y1MIpkYIpHs2beB3enePThU3OWLQxD3dl9w6LQuVH8haiNj+nxRlKG8KQuLlaxDoLyRxnsoVyhIrGMFHOxRWOtyC0vCczdyUVqpPinbXUQEAxxFFsx0SXBnb+jA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152871; c=relaxed/simple; bh=z0csyQTjaj+C9yhlJD2YwA9SB2zPsh7lfK9AhF+081E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mURvUunrxqRIrDBfq2wpTsZ9PcgHKyi3zn8TmM8kNemSu4maAywitKnLYXtWRORNn4Tw+p4TCsanBVbNj7B5XGWph/q05JZ6KIc4s8/DNSz8TKeuuomY7H9IOaocGOWebWOe9z7dH9g3WfbjyvaXvvIRGCQXgIji7sMc86wYG6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=WSkheO3q; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="WSkheO3q" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43117ed8adbso9214905e9.2 for ; Thu, 17 Oct 2024 01:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152868; x=1729757668; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OHDTJ05rGXvacOTESnBohjwJkgn6HYTuHVXiH2uivgs=; b=WSkheO3qyWCWj1gJb3YN/+wsjButcnQ0PDnEY3DeWFU+hD5T6VxUVbkBQzsXTiifAK w9JsGQ+PsZHlRMqAGLOYfx1i/2XPhxoCuQe4nEI1qWRQ0FxMFRVQCBSkT3M8qmXoBp// 2CUSYBxr2yo6WWKW9R++FxXDCi5a1V0JUUYOV27hQV76PuH7XeCGhaJXb1MnKSfB1daS ROpYuZwzy+0QDXJbB9Or+3R6VLwPhn5ijHrMj79O6AC23xUOABROITrPilYdB8RFJ5NB IqKV16WElE0mLuOB7vOe3bB4pewZ8mn8Ffk/tIpM/fudYDkKMJQZm4oJhFvgIZddw2yQ 7Q2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152868; x=1729757668; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OHDTJ05rGXvacOTESnBohjwJkgn6HYTuHVXiH2uivgs=; b=NBuqrR48hkvXA/gSDBS0gzEtD2HQRSGGWCuSz3xuVZqv32PMC8ZOh9jeqKkLNE+zeH 6M0kA4seP1R5jwLUo5iCR1JWxAz8EZp5njiPnXIOMHm6tq1DBHEbsPv7RzEgnnOoGUIT I++/XuDWQ5afJPt8KJ9EKig9Wz0UHfVT513PDEZC55G5fIZ8GcXLgtxn97ZHt15S//ZQ f5PXsdEQsW3J4kq3LgbUeQ6i1+OopkoljuSynGsL7XafObrLdu9scbc15W3xtUjb0iCh ZEhgqY/CnpzJSY7imk+kUn9EHRnjvYbD3ZXcGBzJiWlBbDmcuSUe2Q47zChM2yCgPa2Y b59A== X-Forwarded-Encrypted: i=1; AJvYcCXaof5rRbItBzAiBeTANJv2vrXA4I48O7+VoJGlbFqZIq9teL/DhULuKIlOJi3gLWL8pyOSGM5W6/MCAXM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzmdb9SuSmxAkndfHv3Np80Ut6vW0i77n407RLKypgRYnFvK5P0 mTFNKG508/RvIl4ZAYqzD85nGCc7Gk7TE0KV8o/Bxr5xX99FoOc1mrsDHj7wQgs= X-Google-Smtp-Source: AGHT+IH3/1WlsDT6/Zc59vQeFvCFJ9N1TfZKMWDWbZ4p5wQUNtEVdd5EZt+NPo7ptrlLM6oENQXwTg== X-Received: by 2002:a05:600c:1c9c:b0:42c:a8cb:6a5a with SMTP id 5b1f17b1804b1-431255df67amr189626375e9.15.1729152867674; Thu, 17 Oct 2024 01:14:27 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:27 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:12 +0200 Subject: [PATCH v4 4/8] gpio: cdev: prepare gpio_desc_to_lineinfo() for being called from atomic Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-4-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2628; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=+3Qa4JomiJeerbr48n315kA/cYd1bccbsc5mhXSvDl0=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMddCQpAjEI8dh0CULt+YwvGOirfxhaucWIq9 KvpIPXrYSOJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXQAKCRARpy6gFHHX conID/48a3ILF52224ZoPRxXd4KVoBkI97PaXpLW+KZLSy70G88RZ4xw63FSkarcHkSBjGlp7tf trUOcNupRtdOnhrh1AE0wbRxZBpWaqROoUeQszN/rV1lfJQvaKBNkS2lMHfnZwnc662y4bW5sW/ LA2s0SeySjZDfr/tv8egzUWylc6O/mxUb8K6y8eylFHCI5Vykb9yzhSd2j1dgcfjZ6ijw/336Ip Rd6IXhY6BV5+3FzG8ntnsTjUC0FiP5yonHH7n6SG+I2IsT7zbvMpuRTFB0vo7EyxXu/4cc+ky4b ZKDoEDyhxkADl99DIOGyp8BQ6UGqohoxs7/kRSvy7Ac12gDNWXPibdPILwgrSYo/n/63btBouvy qtWEmlCOk/fzbhqwD0dW5VmpgiU2CcfM3eCs3/CAJOM5izX9uS+jPwde9Kd+Ug0d+Ryvm3YuOHF K1dMTfqh/K1XfO1EbOoPo5FkVjuw2X8WazwBRAKVQk24TLoE9OWKyMM98C1smfClxE4QYPeHJ4Y VcnHQu95ft08yPwSgb1I4Cm2koldNk/a8+Sqa9Q3qkgl/wqi59D7mTaKXI0pxejsAcXvc1WAjA3 DCLSSmjp2zSlAGNGCku1PnXUn8MrKPi2Q54Qe5umHNqDBcTIKazgfYW7PieYIqj084H88a6BGzN kJbyGX8zgMwyOIg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to prepare gpio_desc_to_lineinfo() to being called from atomic context, add a new argument - bool atomic - which, if set, indicates that no sleeping functions must be called (currently: only pinctrl_gpio_can_use_line()). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index d55d2a246d41..0cba74381687 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2235,7 +2235,7 @@ static void gpio_v2_line_info_changed_to_v1( #endif /* CONFIG_GPIO_CDEV_V1 */ =20 static void gpio_desc_to_lineinfo(struct gpio_desc *desc, - struct gpio_v2_line_info *info) + struct gpio_v2_line_info *info, bool atomic) { u32 debounce_period_us; unsigned long dflags; @@ -2277,9 +2277,12 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *= desc, test_bit(FLAG_USED_AS_IRQ, &dflags) || test_bit(FLAG_EXPORT, &dflags) || test_bit(FLAG_SYSFS, &dflags) || - !gpiochip_line_is_valid(guard.gc, info->offset) || - !pinctrl_gpio_can_use_line(guard.gc, info->offset)) + !gpiochip_line_is_valid(guard.gc, info->offset)) { info->flags |=3D GPIO_V2_LINE_FLAG_USED; + } else if (!atomic) { + if (!pinctrl_gpio_can_use_line(guard.gc, info->offset)) + info->flags |=3D GPIO_V2_LINE_FLAG_USED; + } =20 if (test_bit(FLAG_IS_OUT, &dflags)) info->flags |=3D GPIO_V2_LINE_FLAG_OUTPUT; @@ -2385,7 +2388,7 @@ static int lineinfo_get_v1(struct gpio_chardev_data *= cdev, void __user *ip, return -EBUSY; } =20 - gpio_desc_to_lineinfo(desc, &lineinfo_v2); + gpio_desc_to_lineinfo(desc, &lineinfo_v2, false); gpio_v2_line_info_to_v1(&lineinfo_v2, &lineinfo); =20 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) { @@ -2422,7 +2425,7 @@ static int lineinfo_get(struct gpio_chardev_data *cde= v, void __user *ip, if (test_and_set_bit(lineinfo.offset, cdev->watched_lines)) return -EBUSY; } - gpio_desc_to_lineinfo(desc, &lineinfo); + gpio_desc_to_lineinfo(desc, &lineinfo, false); =20 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) { if (watch) @@ -2514,7 +2517,7 @@ static int lineinfo_changed_notify(struct notifier_bl= ock *nb, memset(&chg, 0, sizeof(chg)); chg.event_type =3D action; chg.timestamp_ns =3D ktime_get_ns(); - gpio_desc_to_lineinfo(desc, &chg.info); + gpio_desc_to_lineinfo(desc, &chg.info, false); =20 ret =3D kfifo_in_spinlocked(&cdev->events, &chg, 1, &cdev->wait.lock); if (ret) --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 483AD1D432D for ; Thu, 17 Oct 2024 08:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; cv=none; b=OUdOM/mVz9fzc3TQCx/i996QQSlyKd5jGNCsYk6cS5XpzGhWBjCm6rgHbRWlyx67SD5dj1GQZbgQoCuE1/kv6kmP0FBolWrQuFGm6Pa4IT8uTwRx4a0jMMYhYFR3+phWf5CyLeF161qaEcRBkQVmn64gMbfLUnVPvj/nr43iNc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; c=relaxed/simple; bh=ShKnfVnA13yZAURxSbfkTfcYBLmCdqbi8FWGA7M737A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gaVDvXbSt0BbW+r3RvHY+BfoRgoTykVELijawl8a4PjpBEX5MBpbmbUleWenHhEwU8vriNluVAdMZBvLS1M8pDg6fq3MTM8BO+XgYiCeMg203RPm+ChUtgbOimWBhqROQsQh8uwGbVujj1blm1OFztKZGDNC6YbTpuOwDM7ByKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=GTwMu2rx; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="GTwMu2rx" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42f6bec84b5so7353125e9.1 for ; Thu, 17 Oct 2024 01:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152869; x=1729757669; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=U0tIf0jtJWFltu4ODvVnK3F2kIEgN0qMoeq7qRt5Wac=; b=GTwMu2rxDD2gO/6jJjiZ8eoFRQ5zG6r0m/jb67a7KIKYrZek/qE00hT/k59q5nxUze MoT1Ft/vNeEkadbafCeva+e5fnSC5qmIDEnvz9FJlAAAe8vSETSOVDqhXCIyAVb3pqRG HQFA9LzIrIJ8KCBARZnAu9vlxtwkDsAQUbrGjUl+aouB+O/3ZxEqTzSiaq10bd/Pw8Fw 7ecHNG9WghLHHwvEpreCJRDiO6OBCNnIQxGsTG6fXEjITbQPL78nECY6rVM5w02sT+kk OkxaeJs2Sf/cA4N4MDCDJUHO9ca5SDr5idc3q+Cd3jVx2O3109UywMKjFndMkBH9Ut9F RCWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152869; x=1729757669; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U0tIf0jtJWFltu4ODvVnK3F2kIEgN0qMoeq7qRt5Wac=; b=oi8/z/JwAhqLskN2Lp/F5tuhgZJTr3MO+9tLeH1VGwprU3BCUhI8Q9rs2Gxz9njn1l s2V5US/jqtAM83lfwvAroUw+aS6OtZirXiw/G1CYkDVZcQ9VTp8MLAZW5BcKfTwnMP7d GGkluASCt9riBldac9/t9zj3ytLSmNVrEboWa5lZ/FB+37yMEi4FF/WrLsNkr4l7BYE0 izu74hPlpcB8MhCvz77Hc+FKf8q7n6MSN70+nVUjA9yc49V48HckEVybqFA4J6pYpQJc tGQVMkHtWFO4MoGjwqLodbWB0dBwrPJuXwH6HGrqqKAygzhtgxMwSBw4mcVnr2BzNaJe 3GbQ== X-Forwarded-Encrypted: i=1; AJvYcCUSonkCPydd3j7TqX8WvUHaz7MmUUwqJ9D31livsyr53HXa0TRU4JBqd6QJ0jecZkM0nnqTXuALxqZVeX8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5jTuYBtE4gMn5yJtHKKKxatSUOFB5kEmdX9orwptJQJcK8clY zmPFDqcHbxkpKcJRwhOTEDMp7tDz1D8zMiSzpEfoKi0SIDECYYnfzFitK4I+t74= X-Google-Smtp-Source: AGHT+IGMTAgLIra3AwC4js0TpQefOyARSjB66JJbjktTXIzzaEulPCK8EZEQPJ+r+DlSkK0sB46KMg== X-Received: by 2002:a05:600c:19c6:b0:430:54a4:5ad7 with SMTP id 5b1f17b1804b1-4314a295480mr58184505e9.1.1729152869469; Thu, 17 Oct 2024 01:14:29 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:28 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:13 +0200 Subject: [PATCH v4 5/8] gpiolib: add a per-gpio_device line state notification workqueue Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-5-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2506; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=0P2NY394anUazMVeFpGs/9LRMhoWr2qMp3sLio3SuhQ=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMddVOmN85FNOqbwEfYAB3HukIVwmEvIMEHLF B9/yJf8WlyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXQAKCRARpy6gFHHX crDmEAC4/89OesDABkpdoqYlHW2PfH2sn5oG7KRFR6qFTp3t+zpvYXzRCZ3KSOg+WxuFTkMCjdE WxSJ1BiaA8TlB+kGKCP37xD4HuzMrtd52hp17AkFYV/4giuJAwrdeSrB44Lvqj1oav6Wk7RRA27 LFQzd0vnWSPytvCq3awxuUriJ9eMWSz9XWfzGplHlT3kAokxiRZnd1rTEJegDPMcLzdgkstZ0Dx ORlmkBmK62iKsW31zkGdBhsVJ0+tMJkYv6ince22DmpKULMe8llCRWgFH8Eq44rR727oST7rA4O nGEx08FDtwXGc4C0LcBd7ned7i8ei6CQ+8TfFArV5UDYpgWpFYg8my5ezJYWkkvo15X+Vw//PO8 K+wCLDq7MdqBfLOpxDi753gpXrcG0wFmg1xJMbfoBxi+fBPZvJR9dywonDOJ0p5C4iqEdSZFa0N 2FQtTqvW/xbVSLXxOoWn4wcCrrJ2EcHot0jb23igDjtgAS/i0YFYdPrdNUTLyhc65Etqv+dRxU1 TM3mMlYGLS2zYslBhHXrcfCY5ipKGc0PsnZaS5N1i0/XMp48lQI+ea2khElxFX2EJJEVH9WIHQB Q/Kv8Qnx7reGIbHWSqXIMApnRG/c40yMcrb7a0iE4F5IA2s6vqz6V+rhwDD5PgY6BNgjOj0fs6M TXbNga2uxdaIVrw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to prepare the line state notification mechanism for working in atomic context as well, add a dedicated, high-priority, ordered workqueue to GPIO device which will be used to queue the events fron any context for them to be emitted always in process context. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 6 ++++++ drivers/gpio/gpiolib.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 0cba74381687..b242fdb1ad28 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2749,6 +2749,11 @@ int gpiolib_cdev_register(struct gpio_device *gdev, = dev_t devt) gdev->chrdev.owner =3D THIS_MODULE; gdev->dev.devt =3D MKDEV(MAJOR(devt), gdev->id); =20 + gdev->line_state_wq =3D alloc_ordered_workqueue(dev_name(&gdev->dev), + WQ_HIGHPRI); + if (!gdev->line_state_wq) + return -ENOMEM; + ret =3D cdev_device_add(&gdev->chrdev, &gdev->dev); if (ret) return ret; @@ -2765,6 +2770,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, d= ev_t devt) =20 void gpiolib_cdev_unregister(struct gpio_device *gdev) { + destroy_workqueue(gdev->line_state_wq); cdev_device_del(&gdev->chrdev, &gdev->dev); blocking_notifier_call_chain(&gdev->device_notifier, 0, NULL); } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 8daba06eb472..8737e1641278 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -17,6 +17,7 @@ #include #include #include +#include =20 #define GPIOCHIP_NAME "gpiochip" =20 @@ -44,6 +45,8 @@ * @list: links gpio_device:s together for traversal * @line_state_notifier: used to notify subscribers about lines being * requested, released or reconfigured + * @line_state_wq: used to emit line state events from a separate thread in + * process context * @device_notifier: used to notify character device wait queues about the= GPIO * device being unregistered * @srcu: protects the pointer to the underlying GPIO chip @@ -70,6 +73,7 @@ struct gpio_device { void *data; struct list_head list; struct blocking_notifier_head line_state_notifier; + struct workqueue_struct *line_state_wq; struct blocking_notifier_head device_notifier; struct srcu_struct srcu; =20 --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 11AC91D2F73 for ; Thu, 17 Oct 2024 08:14:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; cv=none; b=R4gzIg/uLquLF9PwmtdlgKwY1F/klktp3iSiO+wNNINI8wiqgJrBE3eo1pZLxB5kOKQEtQO8ZdjuAxklvZrvirmn31BWZMhH5J67ip5hZkxv7ufUc8S/52wqoX1Wf9kXemoxxd45cDPa/jrj1G41QRVGtEkdBO1ffdLu4lkKfac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; c=relaxed/simple; bh=PrpJFSn1v8nec0wiPaBWRUGeCDKvtDkJixy1vIPLnV0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=maWHtHAD2/jDhTiz36HnDGukiMsKln+L5uO+Vj+Z6cnt2js4BT2KtjPN6Wov+cAO6D2v0sP6ffnEF39AmAfsD51/KLD37MOeb6gYBqspRtzqNbhYLuVMnG7G53GcKHUfx7mWy02+r3g7OAxc9uLIefa2xo7lkN47LCW3AIqfXMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Qo9Y/87l; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Qo9Y/87l" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-37d4c1b1455so527987f8f.3 for ; Thu, 17 Oct 2024 01:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152871; x=1729757671; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IQ9+jptp7Dks8GR7GteYZhyJSD9aHU2HeME8AuCmILE=; b=Qo9Y/87lO3P/nODRAVmqG/Xg3U+B0Vb6jfcD6zo5PFIdtLnsWzcS47FhPwFI/Tcixn f/oOqPZvehFR/Ej4rIgWgfA0g6psGOHIoGUBuH7P8uCoa6XZQE0hCllEpwZrf/OGHlFj bgMh2orUInAvXSktP25wQojYkLDwj3Vp8LezdtdPTTaM/hBSqsBKxT3xRO0OJOYMKyx0 w9DZAodfl2EmS0yW796hEKBRB0HpzXCox3HrSxGnGo31abRBQzoLn1XQykIghw+jr5V5 z+/Nnj4c3MIMWFA6cHaLGOe5hbRFx7pSfLfTLH3iSE5bdEnOIgzzWO3aNcJHlNp11uFE 7nVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152871; x=1729757671; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IQ9+jptp7Dks8GR7GteYZhyJSD9aHU2HeME8AuCmILE=; b=O5kj7sWxU1AKBKG470CAjC1lxQJw+UkWC2aGI4sp1/fmWPVd1NPHi6WpMuByajgg43 J4olaZ8l23NsufMoGhzbNkrFB4LhNf+sPVpTWggGg4L8o/qgyC7N3GjqJj/XzYgJvLFL uwV6Mnbuph1AB32PjNefxEJhTvDqHUgUrfzBTEjVHIzMSad8AdeArySQdNH2XYfv0nZZ 5txXEMx4iYP1NpJ6wVILd/4m9jRZ2TQxMLs6wSU4HJuJ+0NO1uzDlbwymznKIyMk4Hgi mHgOU0xs6iwX35dn2BRTmRuEwUvYa5RhRriaP7acExRPHJ16Z7tmR37rTQ5zzqdWawrb vLNA== X-Forwarded-Encrypted: i=1; AJvYcCX1qrNGvR95aqXHK63lwsFKGlw7k+vDVBqLSMg/JKrCkHMjB9G3AHleT4Qw9MLK82plf+ae8InS2EOmbJU=@vger.kernel.org X-Gm-Message-State: AOJu0YyuNd/XJe7QNwDXJ1fdU1Yflw9Vhf31Tf+Cg5FaG5eIfeVR8Wtf 5MTjhNkmav5Rj9qe59Z9pMHaAHrZG0cHza276OToTmoiiCm7MrKIwpUtZeX5BuE= X-Google-Smtp-Source: AGHT+IFp91K7aB+pkhTWU5PY3/I1G7XdXkQZ/Im9BRoGn8XOuM5lVIYcdL35JpTmPY+jKUHhfHHsvw== X-Received: by 2002:a5d:53cd:0:b0:37c:c4bc:181c with SMTP id ffacd0b85a97d-37d55184de1mr14688262f8f.11.1729152871206; Thu, 17 Oct 2024 01:14:31 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:29 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:14 +0200 Subject: [PATCH v4 6/8] gpio: cdev: put emitting the line state events on a workqueue Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-6-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4814; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=8oH0OI5uVpWymK+8p6k+EMIaU2WzdTdaL9nSO2G6k4U=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMdeWUyYkvPl7I78riyiWYJVx4BYSRlNCtrtg LE7hAGq8XaJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXgAKCRARpy6gFHHX cihHEADF1jNbnrL74iwG7sGU7ba916dZuIrsffm24qBZWXgej8JqhlYO/O0rKDMnAppERCpjsL4 mfLFjLN/u/RTLOBxRy6cgQpCoWeDKYkj7KKf/6T9dR63GiErCusSOCSYLzV3QbBpB6yI79AAxsV 6skhRcLNNIEpE1VUPdAdByRNmb3ncm0mIofSuLOfElrvVsqSo9ArZEgqcNVs8acW7IuclxoGQPN wjaWvBJhWen03AkdLwoKQUQQ2w2UeKVpSlfSENK2+GHfy+VpmNv+OQWbLg6FRc6gv2WxIVinM2i c4PrGc8BcZAGhu24WZcqkcEZVziOQ6JjDeZA584FZYxRiv+wa/JKVO7ajppIRN5prkSY9mzGBSl eTBqufaeTaUvBqyg9gavvx2zmBEGvmC2sNNX53lFO+ZLA9BlxC5Kgnwle1awYMWp1cVtIyTqK5O RUP56s+Dia7t2C2BA+rC1PP2c/z9j9HGSPZiUqCbVzTc+waKu0j+86yVbDpl7BHIU41VVWXICs4 XlZTgM3Jo2+DtnslQcNMsiS5D016n4IVQu6+zfikJP2v9i7BgWXmiZVkchJPKsf4eBtQqMH4H1L 2r5laGqKrRp3JIwhJt5PoNHSSHwhCCMCkgWblDrruWFQ+T1y1k7aRggDdve39bJG5VfQve/h0Xn y4THTRKYjkR2pog== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to allow line state notifications to be emitted from atomic context (for instance: from gpiod_direction_input/output()), we must stop calling any sleeping functions in lineinfo_changed_notify(). To that end let's use the new workqueue. Let's atomically allocate small structures containing the required data and fill it with information immediately upon being notified about the change except for the pinctrl state which will be retrieved later from process context. We can pretty reliably do this as pin functions are typically set once per boot. Let's make sure to bump the reference count of GPIO device and the GPIO character device file descriptor to keep both alive until the event was queued. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 82 +++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index b242fdb1ad28..7759dca92f8b 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2333,6 +2333,7 @@ struct gpio_chardev_data { #ifdef CONFIG_GPIO_CDEV_V1 atomic_t watch_abi_version; #endif + struct file *fp; }; =20 static int chipinfo_get(struct gpio_chardev_data *cdev, void __user *ip) @@ -2502,28 +2503,86 @@ static long gpio_ioctl_compat(struct file *file, un= signed int cmd, } #endif =20 +struct lineinfo_changed_ctx { + struct work_struct work; + struct gpio_v2_line_info_changed chg; + struct gpio_device *gdev; + struct gpio_chardev_data *cdev; +}; + +static void lineinfo_changed_func(struct work_struct *work) +{ + struct lineinfo_changed_ctx *ctx =3D + container_of(work, struct lineinfo_changed_ctx, work); + struct gpio_chip *gc; + int ret; + + if (!(ctx->chg.info.flags & GPIO_V2_LINE_FLAG_USED)) { + /* + * If nobody set the USED flag earlier, let's see with pinctrl + * now. We're doing this late because it's a sleeping function. + * Pin functions are in general much more static and while it's + * not 100% bullet-proof, it's good enough for most cases. + */ + scoped_guard(srcu, &ctx->gdev->srcu) { + gc =3D srcu_dereference(ctx->gdev->chip, &ctx->gdev->srcu); + if (gc && + !pinctrl_gpio_can_use_line(gc, ctx->chg.info.offset)) + ctx->chg.info.flags |=3D GPIO_V2_LINE_FLAG_USED; + } + } + + ret =3D kfifo_in_spinlocked(&ctx->cdev->events, &ctx->chg, 1, + &ctx->cdev->wait.lock); + if (ret) + wake_up_poll(&ctx->cdev->wait, EPOLLIN); + else + pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); + + gpio_device_put(ctx->gdev); + fput(ctx->cdev->fp); + kfree(ctx); +} + static int lineinfo_changed_notify(struct notifier_block *nb, unsigned long action, void *data) { struct gpio_chardev_data *cdev =3D container_of(nb, struct gpio_chardev_data, lineinfo_changed_nb); - struct gpio_v2_line_info_changed chg; + struct lineinfo_changed_ctx *ctx; struct gpio_desc *desc =3D data; - int ret; =20 if (!test_bit(gpio_chip_hwgpio(desc), cdev->watched_lines)) return NOTIFY_DONE; =20 - memset(&chg, 0, sizeof(chg)); - chg.event_type =3D action; - chg.timestamp_ns =3D ktime_get_ns(); - gpio_desc_to_lineinfo(desc, &chg.info, false); + /* + * If this is called from atomic context (for instance: with a spinlock + * taken by the atomic notifier chain), any sleeping calls must be done + * outside of this function in process context of the dedicated + * workqueue. + * + * Let's gather as much info as possible from the descriptor and + * postpone just the call to pinctrl_gpio_can_use_line() until the work + * is executed. + */ =20 - ret =3D kfifo_in_spinlocked(&cdev->events, &chg, 1, &cdev->wait.lock); - if (ret) - wake_up_poll(&cdev->wait, EPOLLIN); - else - pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); + ctx =3D kzalloc(sizeof(*ctx), GFP_ATOMIC); + if (!ctx) { + pr_err("Failed to allocate memory for line info notification\n"); + return NOTIFY_DONE; + } + + ctx->chg.event_type =3D action; + ctx->chg.timestamp_ns =3D ktime_get_ns(); + gpio_desc_to_lineinfo(desc, &ctx->chg.info, true); + /* Keep the GPIO device alive until we emit the event. */ + ctx->gdev =3D gpio_device_get(desc->gdev); + ctx->cdev =3D cdev; + /* Keep the file descriptor alive too. */ + get_file(ctx->cdev->fp); + + INIT_WORK(&ctx->work, lineinfo_changed_func); + queue_work(ctx->gdev->line_state_wq, &ctx->work); =20 return NOTIFY_OK; } @@ -2683,6 +2742,7 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) goto out_unregister_line_notifier; =20 file->private_data =3D cdev; + cdev->fp =3D file; =20 ret =3D nonseekable_open(inode, file); if (ret) --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 C03291D5CCF for ; Thu, 17 Oct 2024 08:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; cv=none; b=ks7nhBWQ7XyBlskX4RSd1TVNScY9laDd2dqlXwHt/4Tbl1Q1ZRKCzBW/+PUZcTrWVF8xhbD44dJBQroS+MWabPAsxCE4Fby4YASqTgfr3pHdJhx3GGtZvjFTToMQhZtYSRbBXRRLP8VQYOb6NbBZOoKcQ51pA2U6j4IrIBP1UF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; c=relaxed/simple; bh=Jc6C6BtaJP7y1Wa50WUZYA4CGv0mhlupt88QoaGx7vU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mm4fa3oYLhdX+JuYpMRN21p0z6RjNPVnH67i/R9BpBL6k7DPyi0nTv62YE1Ep+7sUbYTnc69ZHKKNFO6mLOqE2cKnWQkuayDp+93ZIzyMsZj+kKpUO2PSzqicX4+VMBSyefbVG7IltTGrIvTidWKhXfU20+JokenGCRbPKKC/9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=q2wqJCy+; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="q2wqJCy+" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43158625112so6277505e9.3 for ; Thu, 17 Oct 2024 01:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152872; x=1729757672; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=REHoi0BzREleJqZ/Nl2V6XA6vWcoShbFDJgBvOZh4is=; b=q2wqJCy+ST2HNlBv/obGdcSBSjDfqppbAEhMtEKt3K6UJJ98VDndT4C7ylllzfkF/T arBTIK54iBMOSNbizskFDQMrIElqYyzNcOaDZdLJRRhSmLcNj0ocykWlpM365Ze7A5pE 7/XgrZbw0Gjj5XaqV/Rlu9L+vPmvijdT9MstzdvgS6bdP28kRixX/0nI3NACHUchmc8K n6SZw+OAT070RrysOBaayaHVUdmTXgNmCAVQnWwwB/Bqgv6NGsFJd/+uIhsGKyeFBUTS SLwF9GChGRtGHJrDieL1+MVF7VE2iOIDtuC15XHT9rDudrPsNtTJKiqPuChvSmP47XCM xygA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152872; x=1729757672; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=REHoi0BzREleJqZ/Nl2V6XA6vWcoShbFDJgBvOZh4is=; b=UtXl66Zmp/ALTvCVYsU25MhQ75PA7Wkcvh3BdqQPvFHUKzWGG6mXEcGin23nS+5byF qGz3P5HaW7gEde0x8kzdeVBaa3njxLHBN0n7SPgrdBdzKBLsn0uga/S+fks2o4jwkPBS FXHsovZjhADxEKJpuU8XLvXkfTS8nZs/cy5utcUy3YNNUqAfa8pr3qH9KXcjbwh1xBt8 BdNZAKKSG4xT/5UkQlHMvESCW47NDTdnjVKxLJCuJDeKXGhDM+hf6HmKmo6IwZkydgll +JpGgbrdH8zuUWhvQrsjoSOaPC+fZympPVthyW+Hyz9XRmuC9Sdn/YTemkT7vgo+JUWU /CZg== X-Forwarded-Encrypted: i=1; AJvYcCWl5ICy7RJ6YL3lNfvh6dPdtWplbCJcb47G4fOft8/QrVObQuAs0tSyWJIQuVLZVzUrghflNfCeasATLZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YzLA8AGDCE9fy22dxrOzehyUFWhjhjpQhwwu1VaBwlz9K6hl/Ax 9YBp1w+hRFzhCII2JVssd5swTWuXwYu1h5e0HusSl++kwzgVMT6Xdj+4dERnK5k= X-Google-Smtp-Source: AGHT+IHl1IrDyN4qqCTCX3GhdMHOxw0XgQiPW7XFdlWOXaoZligJ9HpEzZe4yEk05etTo9uqWBs9iA== X-Received: by 2002:a05:600c:3d89:b0:426:5ef5:bcb1 with SMTP id 5b1f17b1804b1-431255d55edmr144095315e9.6.1729152871940; Thu, 17 Oct 2024 01:14:31 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:31 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:15 +0200 Subject: [PATCH v4 7/8] gpiolib: switch the line state notifier to atomic Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-7-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3446; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=JremVAHUv8l5XF85K04PimL7Ca9vBLgcOvsxmUmBC6Y=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMdeqvCdrahsiwFUY+YJY5Bs2rgQfuM6FNsvE zxyuHeRTdCJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXgAKCRARpy6gFHHX crg1D/49zyA6qTTp2Dqj9QWMfbL2YIIIFAYQk7boqVgR6QyXwhLN0cEsB8CVh8donSyhFIcpjW1 5hd+QyR468qYZyhGqo/pgyh1zanCyhQaeJvz+JhV890kP2AZeWgdJmJGeG7sVQCKizznvmWKYKP BOTl3WtDnznfVYou2hpH494gsxQ24S5GUw/XZcY0fJGC3ACAPLEZuU93bRJh20YiPfdeCNQhAEd AhYXj7We+kBEnc4h++/WT0zV9qom3ebd9sOj2dfm2/Si55EBEnjkUIdhq74ZKOvJJR/djQHhyzQ xYJcmewAVrUI169+6FMLOIr9mppoLNmWqPvrK/x5nWrQnjzhwXLhEDtYtWKTyottFqfE1DMIWgo W6X2QleXGjtbpyPUZp4mzRVnJGU6hozS/lFiibLcm6RwoUdJuLhZSPrXbSmCtFaTvit20JEj8pK VNzS9L4FoyuHbNOIJeafE+BeqSgZi36CWflTTmvTzPnagMbVreEid/TTVfL11FyTMc2XZbaAXZZ cWW9p3EPj50ZrYP3CHmQk2cuQ45LaMz0zbhoSBf+joxVDus1ZNf9MK2YFV2aA85rax6I+pOkOT/ QL01TesybaBamBBgKABF88kq0RBH6auLqt6WhiYhq4bM2+YFH1QplLofHHVgmTbZ9fqN6LIsWui h5za3umPvLuXlLw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski With everything else ready, we can now switch to using the atomic notifier for line state events which will allow us to notify user-space about direction changes from atomic context. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 12 ++++++------ drivers/gpio/gpiolib.c | 6 +++--- drivers/gpio/gpiolib.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 7759dca92f8b..cb4fb55e2696 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2729,8 +2729,8 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) cdev->gdev =3D gpio_device_get(gdev); =20 cdev->lineinfo_changed_nb.notifier_call =3D lineinfo_changed_notify; - ret =3D blocking_notifier_chain_register(&gdev->line_state_notifier, - &cdev->lineinfo_changed_nb); + ret =3D atomic_notifier_chain_register(&gdev->line_state_notifier, + &cdev->lineinfo_changed_nb); if (ret) goto out_free_bitmap; =20 @@ -2754,8 +2754,8 @@ static int gpio_chrdev_open(struct inode *inode, stru= ct file *file) blocking_notifier_chain_unregister(&gdev->device_notifier, &cdev->device_unregistered_nb); out_unregister_line_notifier: - blocking_notifier_chain_unregister(&gdev->line_state_notifier, - &cdev->lineinfo_changed_nb); + atomic_notifier_chain_unregister(&gdev->line_state_notifier, + &cdev->lineinfo_changed_nb); out_free_bitmap: gpio_device_put(gdev); bitmap_free(cdev->watched_lines); @@ -2779,8 +2779,8 @@ static int gpio_chrdev_release(struct inode *inode, s= truct file *file) =20 blocking_notifier_chain_unregister(&gdev->device_notifier, &cdev->device_unregistered_nb); - blocking_notifier_chain_unregister(&gdev->line_state_notifier, - &cdev->lineinfo_changed_nb); + atomic_notifier_chain_unregister(&gdev->line_state_notifier, + &cdev->lineinfo_changed_nb); bitmap_free(cdev->watched_lines); gpio_device_put(gdev); kfree(cdev); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 807bee86afd5..83e85dbfdeed 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1026,7 +1026,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, } } =20 - BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); + ATOMIC_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); =20 ret =3D init_srcu_struct(&gdev->srcu); @@ -4098,8 +4098,8 @@ EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep); =20 void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action) { - blocking_notifier_call_chain(&desc->gdev->line_state_notifier, - action, desc); + atomic_notifier_call_chain(&desc->gdev->line_state_notifier, + action, desc); } =20 /** diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 8737e1641278..a54be597d21a 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -72,7 +72,7 @@ struct gpio_device { const char *label; void *data; struct list_head list; - struct blocking_notifier_head line_state_notifier; + struct atomic_notifier_head line_state_notifier; struct workqueue_struct *line_state_wq; struct blocking_notifier_head device_notifier; struct srcu_struct srcu; --=20 2.43.0 From nobody Tue Nov 26 15:33:41 2024 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 B05A31D63DC for ; Thu, 17 Oct 2024 08:14:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152880; cv=none; b=g9U5gVQ4SvNp6smJQ1pF52dFkopSRHDRDYx0NxD56haytFUxuTSv3Hu9vMurpf78gtM+QK+WxyEceuuSLlGVEl0a9dtvP/9PLtPPBIVICrWz7ID5eh1f+DEkdU/rDCFLY9odsw/D5QZVTQEFMBf2CMQ4y58Qufg44bbTPCrYV/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152880; c=relaxed/simple; bh=c4J/UnmFeTC8BBvqpEPvj+zBWvdybelwThrbdTexxsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OIup6cNXcOPdSw+ocIi8GXFpLFzkZoFX127bsbcCxsoflgTaR1qdPKXo5iZD6IuuJYni21FVl9ocbRpf/D5QqevgZLQy7kq2Eigiba8/uwzkdxTcO5PQtnrpmdxM81+AfJlny+6DT6IB4MOTd27u+nSyVgkyBlbEE7Okomq5Txw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=CH8HFPBQ; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="CH8HFPBQ" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-539d9fffea1so665493e87.2 for ; Thu, 17 Oct 2024 01:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152874; x=1729757674; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PbuZ78Ln+IyEolb1HzZUdx3L9NhHInxuuhSiBS2bsdw=; b=CH8HFPBQVmkyWkDTH/4eJo81QL9e7vg4lcoOu9rFPKRjDBA68WGrGrnUH6h+gDHBTg eLctkTgKN+921NEix6e4TTO2VVKP1euj9tM5odybdxTHVSkC4xnsjODps7zOlKErbIk8 6F8G9oZlZqgfahpHSN9hujle1vt02zlcnl70VKGPqmQ344ExDvVszPV0pTIo/IQoz4Ft LxEgEgKdzb6+zaNv23SgdHRsRT/9acshjuH8nUf7JR/KY3D2Yz1Jz9MnWed6MeP4ubgy IIdrNeRG2hiAj6Az1K8xhkOurrr+RGZ+ipUWPWGEQXawyCSq7QpzmrsHMfkVEGT2E2W6 zhaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152874; x=1729757674; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PbuZ78Ln+IyEolb1HzZUdx3L9NhHInxuuhSiBS2bsdw=; b=DKDX9anU45I+rbZyPo38hGUQ4LXMzxVGwX99cVLQe/G2lQuJmvl3tRCbRU/CiWsNgw iS6996S1iVrnkv99IY1aCvVHwalM2tqbehBKJOIqxobThLUYXdIHQy9kUL6sOfLTpW2w NnMNEbEmnrJPDNkNrYrM1nqoLi2Km1Kd9K3evJsLq8AsrgvOSH4TG4cRAX+LXSm4FGSl qz6d739eTFrD9kRT8gfM6Qx7qMDcOZEBAAm9dosCGFwu22H1aqAeW4DvIdd4fDA8fXo1 D4dORsz1FsPJ/V50HJBnE3HEKrOzm1H9gC4KY6DJ0BHBO/FdkPUYeArgzYdc1VdM0d8E 78Mg== X-Forwarded-Encrypted: i=1; AJvYcCVBV5hok9lRXHixFilN6EGQLI/I2HFVCMrem/WVgQEqwAQp3d8oJh5ocxxUTEiQQ4C2bQoUpDpH15Y4nuA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4K3j7KG5BBUUspzMsSsYOgTxNCtXz6ytIZbMqCW1Eda2pCnIS l9moQcKeWkHOiods+QprCJPZzYyew7/Dhlp2nW0AULSj0QbM09xOJU0ak7bXf4I= X-Google-Smtp-Source: AGHT+IFsdnLfre4VUn+fGt/EEvLeGGxoNYWlklN1Qtb26Tpi/U+IR84E/vYlf3U3mKqtTAVgkVhvhQ== X-Received: by 2002:a05:6512:15a3:b0:53a:16b:f14f with SMTP id 2adb3069b0e04-53a03f18f73mr4462551e87.19.1729152873677; Thu, 17 Oct 2024 01:14:33 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:32 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:16 +0200 Subject: [PATCH v4 8/8] gpiolib: notify user-space about in-kernel line state changes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241017-gpio-notify-in-kernel-events-v4-8-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=10442; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=e8xh0s9h71X8kX5zh7fMViHQeVImY96zS9zoeZtXFFg=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEMde5h3fbG0F5bR5wB6hqFmrmugKR8hatvfTW ImLhmD4jROJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXgAKCRARpy6gFHHX cu1WD/0byuH1vtfPfxy8vKHI0EqW1fnYIKCuV9zjvzpBPDv1TuCbpApKU+m2VQA0xvhvq5Z5vkz gfH6KotfOh6elx4t7sysCx8+GRzKcTfWWhLEyX2HQxlqifm4H1xzIWjqS217DVyS7UJDUE3CD3a +6ibFRuvJVywrQw9bP0X1gyXPh8W5KOPn+8G/2e7YrgW/wKgLoJEHdLtueq78+77V90q1LidYVA CjGMsS3id1Kt8H00djDbQsd11dRVoe+yaQ5B/5Hpwh9PHUhsEoH7s5YHBhWHThRUptNF/4RAcg/ FHZj2qCBPnp7OrP1ineysuHjpHlztYGJiwIxlGNW5dhEp8uYM89QZDC5ZFh9m8S6pV/J1bWd7ha XAO6gcVF/8nqMvDHkYSBA0UDIg1mK8/fyn+hhLJ9Lq2zBYmVcLQGcV7syW2WWRsKYA/h+n/aiY+ 6he8yXw6U3vByRo/G7E4q/iNlggzXd3TOqzn7JGUSmpMh8nRhp9M6BxCfS55dr4Xh7Fjr/BHkBp OgFrxTKfYQAHrO21J+vM8+/QlsGMPbCVwg0WiIWZkwLPmVPp0+R/AJ9xzKD7azSNsEt5UTUe+V0 5Ixzrel8t1VAzguKU12dUL1mH2GElQlyIuIA8ujfKlylEAuBzCWoFX//1lVGRxKMKmF6EA74A8S Fz5vQoX7gG2C3FQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We currently only notify user-space about line config changes that are made from user-space. Any kernel config changes are not signalled. Let's improve the situation by emitting the events closer to the source. To that end let's call the relevant notifier chain from the functions setting direction, gpiod_set_config(), gpiod_set_consumer_name() and gpiod_toggle_active_low(). This covers all the options that we can inform the user-space about. We ignore events which don't have corresponding flags exported to user-space on purpose - otherwise the user would see a config-changed event but the associated line-info would remain unchanged. gpiod_direction_output/input() can be called from any context. Fortunately, we now emit line state events using an atomic notifier chain, so it's no longer an issue. Let's also add non-notifying wrappers around the direction setters in order to not emit superfluous reconfigure events when requesting the lines as the initial config should be part of the request notification. Use gpio_do_set_config() instead of gpiod_set_debounce() for configuring debouncing via hardware from the character device code to avoid multiple reconfigure events. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 21 ++++++----- drivers/gpio/gpiolib.c | 89 ++++++++++++++++++++++++++++++++++++++---= ---- drivers/gpio/gpiolib.h | 3 ++ 3 files changed, 90 insertions(+), 23 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index cb4fb55e2696..e5b15d96e952 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -195,8 +195,6 @@ static long linehandle_set_config(struct linehandle_sta= te *lh, if (ret) return ret; } - - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); } return 0; } @@ -362,11 +360,11 @@ static int linehandle_create(struct gpio_device *gdev= , void __user *ip) if (lflags & GPIOHANDLE_REQUEST_OUTPUT) { int val =3D !!handlereq.default_values[i]; =20 - ret =3D gpiod_direction_output(desc, val); + ret =3D gpiod_direction_output_nonotify(desc, val); if (ret) goto out_free_lh; } else if (lflags & GPIOHANDLE_REQUEST_INPUT) { - ret =3D gpiod_direction_input(desc); + ret =3D gpiod_direction_input_nonotify(desc); if (ret) goto out_free_lh; } @@ -922,8 +920,13 @@ static int debounce_setup(struct line *line, unsigned = int debounce_period_us) int ret, level, irq; char *label; =20 - /* try hardware */ - ret =3D gpiod_set_debounce(line->desc, debounce_period_us); + /* + * Try hardware. Skip gpiod_set_config() to avoid emitting two + * CHANGED_CONFIG line state events. + */ + ret =3D gpio_do_set_config(line->desc, + pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, + debounce_period_us)); if (!ret) { WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); return ret; @@ -1447,8 +1450,6 @@ static long linereq_set_config(struct linereq *lr, vo= id __user *ip) } =20 WRITE_ONCE(line->edflags, edflags); - - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); } return 0; } @@ -1700,11 +1701,11 @@ static int linereq_create(struct gpio_device *gdev,= void __user *ip) if (flags & GPIO_V2_LINE_FLAG_OUTPUT) { int val =3D gpio_v2_line_config_output_value(lc, i); =20 - ret =3D gpiod_direction_output(desc, val); + ret =3D gpiod_direction_output_nonotify(desc, val); if (ret) goto out_free_linereq; } else if (flags & GPIO_V2_LINE_FLAG_INPUT) { - ret =3D gpiod_direction_input(desc); + ret =3D gpiod_direction_input_nonotify(desc); if (ret) goto out_free_linereq; =20 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 83e85dbfdeed..ae758ba6dc3d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2564,7 +2564,7 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); * rely on gpio_request() having been called beforehand. */ =20 -static int gpio_do_set_config(struct gpio_desc *desc, unsigned long config) +int gpio_do_set_config(struct gpio_desc *desc, unsigned long config) { int ret; =20 @@ -2670,9 +2670,15 @@ static int gpio_set_bias(struct gpio_desc *desc) */ int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounc= e) { - return gpio_set_config_with_argument_optional(desc, - PIN_CONFIG_INPUT_DEBOUNCE, - debounce); + int ret; + + ret =3D gpio_set_config_with_argument_optional(desc, + PIN_CONFIG_INPUT_DEBOUNCE, + debounce); + if (!ret) + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + + return ret; } =20 /** @@ -2686,6 +2692,18 @@ int gpio_set_debounce_timeout(struct gpio_desc *desc= , unsigned int debounce) * 0 on success, or negative errno on failure. */ int gpiod_direction_input(struct gpio_desc *desc) +{ + int ret; + + ret =3D gpiod_direction_input_nonotify(desc); + if (ret =3D=3D 0) + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + + return ret; +} +EXPORT_SYMBOL_GPL(gpiod_direction_input); + +int gpiod_direction_input_nonotify(struct gpio_desc *desc) { int ret =3D 0; =20 @@ -2733,7 +2751,6 @@ int gpiod_direction_input(struct gpio_desc *desc) =20 return ret; } -EXPORT_SYMBOL_GPL(gpiod_direction_input); =20 static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int v= alue) { @@ -2795,8 +2812,15 @@ static int gpiod_direction_output_raw_commit(struct = gpio_desc *desc, int value) */ int gpiod_direction_output_raw(struct gpio_desc *desc, int value) { + int ret; + VALIDATE_DESC(desc); - return gpiod_direction_output_raw_commit(desc, value); + + ret =3D gpiod_direction_output_raw_commit(desc, value); + if (ret =3D=3D 0) + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + + return ret; } EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); =20 @@ -2814,6 +2838,18 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); * 0 on success, or negative errno on failure. */ int gpiod_direction_output(struct gpio_desc *desc, int value) +{ + int ret; + + ret =3D gpiod_direction_output_nonotify(desc, value); + if (ret =3D=3D 0) + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + + return ret; +} +EXPORT_SYMBOL_GPL(gpiod_direction_output); + +int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value) { unsigned long flags; int ret; @@ -2843,7 +2879,7 @@ int gpiod_direction_output(struct gpio_desc *desc, in= t value) goto set_output_value; /* Emulate open drain by not actively driving the line high */ if (value) { - ret =3D gpiod_direction_input(desc); + ret =3D gpiod_direction_input_nonotify(desc); goto set_output_flag; } } else if (test_bit(FLAG_OPEN_SOURCE, &flags)) { @@ -2852,7 +2888,7 @@ int gpiod_direction_output(struct gpio_desc *desc, in= t value) goto set_output_value; /* Emulate open source by not actively driving the line low */ if (!value) { - ret =3D gpiod_direction_input(desc); + ret =3D gpiod_direction_input_nonotify(desc); goto set_output_flag; } } else { @@ -2876,7 +2912,6 @@ int gpiod_direction_output(struct gpio_desc *desc, in= t value) set_bit(FLAG_IS_OUT, &desc->flags); return ret; } -EXPORT_SYMBOL_GPL(gpiod_direction_output); =20 /** * gpiod_enable_hw_timestamp_ns - Enable hardware timestamp in nanoseconds. @@ -2955,9 +2990,30 @@ EXPORT_SYMBOL_GPL(gpiod_disable_hw_timestamp_ns); */ int gpiod_set_config(struct gpio_desc *desc, unsigned long config) { + int ret; + VALIDATE_DESC(desc); =20 - return gpio_do_set_config(desc, config); + ret =3D gpio_do_set_config(desc, config); + if (!ret) { + /* These are the only options we notify the userspace about. */ + switch (pinconf_to_config_param(config)) { + case PIN_CONFIG_BIAS_DISABLE: + case PIN_CONFIG_BIAS_PULL_DOWN: + case PIN_CONFIG_BIAS_PULL_UP: + case PIN_CONFIG_DRIVE_OPEN_DRAIN: + case PIN_CONFIG_DRIVE_OPEN_SOURCE: + case PIN_CONFIG_DRIVE_PUSH_PULL: + case PIN_CONFIG_INPUT_DEBOUNCE: + gpiod_line_state_notify(desc, + GPIO_V2_LINE_CHANGED_CONFIG); + break; + default: + break; + } + } + + return ret; } EXPORT_SYMBOL_GPL(gpiod_set_config); =20 @@ -3024,6 +3080,7 @@ void gpiod_toggle_active_low(struct gpio_desc *desc) { VALIDATE_DESC_VOID(desc); change_bit(FLAG_ACTIVE_LOW, &desc->flags); + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); } EXPORT_SYMBOL_GPL(gpiod_toggle_active_low); =20 @@ -3668,9 +3725,15 @@ EXPORT_SYMBOL_GPL(gpiod_cansleep); */ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) { + int ret; + VALIDATE_DESC(desc); =20 - return desc_set_label(desc, name); + ret =3D desc_set_label(desc, name); + if (ret =3D=3D 0) + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + + return ret; } EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); =20 @@ -4548,10 +4611,10 @@ int gpiod_configure_flags(struct gpio_desc *desc, c= onst char *con_id, =20 /* Process flags */ if (dflags & GPIOD_FLAGS_BIT_DIR_OUT) - ret =3D gpiod_direction_output(desc, + ret =3D gpiod_direction_output_nonotify(desc, !!(dflags & GPIOD_FLAGS_BIT_DIR_VAL)); else - ret =3D gpiod_direction_input(desc); + ret =3D gpiod_direction_input_nonotify(desc); =20 return ret; } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index a54be597d21a..83690f72f7e5 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -155,6 +155,8 @@ int gpiod_set_array_value_complex(bool raw, bool can_sl= eep, int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); =20 void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action); +int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value); +int gpiod_direction_input_nonotify(struct gpio_desc *desc); =20 struct gpio_desc_label { struct rcu_head rh; @@ -258,6 +260,7 @@ struct gpio_desc *gpiod_find_and_request(struct device = *consumer, const char *label, bool platform_lookup_allowed); =20 +int gpio_do_set_config(struct gpio_desc *desc, unsigned long config); int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, unsigned long lflags, enum gpiod_flags dflags); int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounc= e); --=20 2.43.0