From patchwork Fri Oct 22 02:00:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1544742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=lmMMOt0e; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hb6yX1c4yz9sNH for ; Fri, 22 Oct 2021 13:01:07 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Hb6yS5yRWz3c8d for ; Fri, 22 Oct 2021 13:01:04 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=lmMMOt0e; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=lmMMOt0e; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Hb6y91fcCz2y7X for ; Fri, 22 Oct 2021 13:00:48 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 30DFA6E4; Thu, 21 Oct 2021 19:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1634868044; bh=GVLa29qKQGMmS8DeLPvKZ38U2JRDGIV1ZE7yFTt1GH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmMMOt0e5ljaeEO5ZFy+7po0VxP4S8djGW9aJ5CR70BF/LwC3M8mbRV98+aRsl/4l C4bQA3K1HiyYKkgHR7gsrDdALj3WR/Koc4mZuAtjI1XW5yeEoxfJJj5mFRlLeMp9uL SJ+0xzgeYTZUSSnMFoJ7+rZo0mWiXC4Nxyuz9ljg= From: Zev Weiss To: Frank Rowand , Greg Kroah-Hartman , Rob Herring Subject: [PATCH 1/5] of: base: add function to check for status = "reserved" Date: Thu, 21 Oct 2021 19:00:28 -0700 Message-Id: <20211022020032.26980-2-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211022020032.26980-1-zev@bewilderbeest.net> References: <20211022020032.26980-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Andrew Jeffery , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Jeremy Kerr Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Per v0.3 of the Devicetree Specification [0]: Indicates that the device is operational, but should not be used. Typically this is used for devices that are controlled by another software component, such as platform firmware. One use-case for this is in OpenBMC, where certain devices (such as a BIOS flash chip) may be shared by the host and the BMC, but cannot be accessed by the BMC during its usual boot-time device probing, because they require additional (potentially elaborate) coordination with the host to arbitrate which processor is controlling the device. Devices marked with this status should thus be instantiated, but not have a driver bound to them or be otherwise touched. [0] https://github.com/devicetree-org/devicetree-specification/releases/download/v0.3/devicetree-specification-v0.3.pdf Signed-off-by: Zev Weiss --- drivers/of/base.c | 56 +++++++++++++++++++++++++++++++++++++++------- include/linux/of.h | 6 +++++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 0ac17256258d..3bd7c5b8a2cc 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -580,14 +580,16 @@ int of_machine_is_compatible(const char *compat) EXPORT_SYMBOL(of_machine_is_compatible); /** - * __of_device_is_available - check if a device is available for use + * __of_device_check_status - check if a device's status matches a particular string * - * @device: Node to check for availability, with locks already held + * @device: Node to check status of, with locks already held + * @val: Status string to check for, or NULL for "okay"/"ok" * - * Return: True if the status property is absent or set to "okay" or "ok", - * false otherwise + * Return: True if status property exists and matches @val, or either "okay" + * or "ok" if @val is NULL, or if status property is absent and @val is + * "okay", "ok", or NULL. False otherwise. */ -static bool __of_device_is_available(const struct device_node *device) +static bool __of_device_check_status(const struct device_node *device, const char *val) { const char *status; int statlen; @@ -596,17 +598,35 @@ static bool __of_device_is_available(const struct device_node *device) return false; status = __of_get_property(device, "status", &statlen); - if (status == NULL) - return true; + if (!status) { + /* a missing status property is treated as "okay" */ + status = "okay"; + statlen = strlen(status) + 1; /* property lengths include the NUL terminator */ + } if (statlen > 0) { - if (!strcmp(status, "okay") || !strcmp(status, "ok")) + if (!val && (!strcmp(status, "okay") || !strcmp(status, "ok"))) + return true; + else if (val && !strcmp(status, val)) return true; } return false; } +/** + * __of_device_is_available - check if a device is available for use + * + * @device: Node to check for availability, with locks already held + * + * Return: True if the status property is absent or set to "okay" or "ok", + * false otherwise + */ +static bool __of_device_is_available(const struct device_node *device) +{ + return __of_device_check_status(device, NULL); +} + /** * of_device_is_available - check if a device is available for use * @@ -628,6 +648,26 @@ bool of_device_is_available(const struct device_node *device) } EXPORT_SYMBOL(of_device_is_available); +/** + * of_device_is_reserved - check if a device is marked as reserved + * + * @device: Node to check for reservation + * + * Return: True if the status property is set to "reserved", false otherwise + */ +bool of_device_is_reserved(const struct device_node *device) +{ + unsigned long flags; + bool res; + + raw_spin_lock_irqsave(&devtree_lock, flags); + res = __of_device_check_status(device, "reserved"); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + + return res; +} +EXPORT_SYMBOL(of_device_is_reserved); + /** * of_device_is_big_endian - check if a device has BE registers * diff --git a/include/linux/of.h b/include/linux/of.h index 6f1c41f109bb..aa9762da5e7c 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -345,6 +345,7 @@ extern int of_device_is_compatible(const struct device_node *device, extern int of_device_compatible_match(struct device_node *device, const char *const *compat); extern bool of_device_is_available(const struct device_node *device); +extern bool of_device_is_reserved(const struct device_node *device); extern bool of_device_is_big_endian(const struct device_node *device); extern const void *of_get_property(const struct device_node *node, const char *name, @@ -707,6 +708,11 @@ static inline bool of_device_is_available(const struct device_node *device) return false; } +static inline bool of_device_is_reserved(const struct device_node *device) +{ + return false; +} + static inline bool of_device_is_big_endian(const struct device_node *device) { return false; From patchwork Fri Oct 22 02:00:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1544746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=dTLcZyfB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hb7172WYwz9sNH for ; Fri, 22 Oct 2021 13:03:23 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Hb7171cH0z3c7l for ; Fri, 22 Oct 2021 13:03:23 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=dTLcZyfB; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=dTLcZyfB; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Hb6yB2yCsz2y7X for ; Fri, 22 Oct 2021 13:00:49 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id AE5E572B; Thu, 21 Oct 2021 19:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1634868046; bh=2efYL9rwju5SdZ2gZO9Y+iw53j+3OthU+D9Ued9171A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dTLcZyfB+o23zCieIixIk1iW6+CXajFlgYvk05xm6r1pcsOB3pmRsMCV71ZWfrEgS TfjbvVP5tlYDrYgv1hZIuIYw5QFffzYmZp35cfj/s+QelYfZ2PBZt6wxNGrkPv2WS1 qCOJbwjPa+skQ+phlmsd1hqHnkxdl1TXK1JgKTxg= From: Zev Weiss To: Frank Rowand , Greg Kroah-Hartman , Rob Herring Subject: [PATCH 2/5] device property: add fwnode_device_is_reserved() Date: Thu, 21 Oct 2021 19:00:29 -0700 Message-Id: <20211022020032.26980-3-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211022020032.26980-1-zev@bewilderbeest.net> References: <20211022020032.26980-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Heikki Krogerus , Saravana Kannan , Zev Weiss , "Rafael J. Wysocki" , Andrew Jeffery , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Daniel Scally , linux-acpi@vger.kernel.org, Jeremy Kerr , Andy Shevchenko , Len Brown Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This is the fwnode API corresponding to of_device_is_reserved(), which indicates that a device exists but may not be immediately accessible. Signed-off-by: Zev Weiss --- drivers/base/property.c | 16 ++++++++++++++++ include/linux/fwnode.h | 2 ++ include/linux/property.h | 1 + 3 files changed, 19 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 453918eb7390..7b70cb04531c 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -845,6 +845,22 @@ bool fwnode_device_is_available(const struct fwnode_handle *fwnode) } EXPORT_SYMBOL_GPL(fwnode_device_is_available); +/** + * fwnode_device_is_reserved - check if a device is reserved for use + * @fwnode: Pointer to the fwnode of the device. + * + * For fwnode node types that don't implement the .device_is_reserved() + * operation, this function returns false. + */ +bool fwnode_device_is_reserved(const struct fwnode_handle *fwnode) +{ + if (!fwnode_has_op(fwnode, device_is_reserved)) + return false; + + return fwnode_call_bool_op(fwnode, device_is_reserved); +} +EXPORT_SYMBOL_GPL(fwnode_device_is_reserved); + /** * device_get_child_node_count - return the number of child nodes for device * @dev: Device to cound the child nodes for diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 9f4ad719bfe3..1a9aefbe12f1 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -86,6 +86,7 @@ struct fwnode_reference_args { * @get: Get a reference to an fwnode. * @put: Put a reference to an fwnode. * @device_is_available: Return true if the device is available. + * @device_is_reserved: Return true if the device is reserved. * @device_get_match_data: Return the device driver match data. * @property_present: Return true if a property is present. * @property_read_int_array: Read an array of integer properties. Return zero on @@ -110,6 +111,7 @@ struct fwnode_operations { struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); void (*put)(struct fwnode_handle *fwnode); bool (*device_is_available)(const struct fwnode_handle *fwnode); + bool (*device_is_reserved)(const struct fwnode_handle *fwnode); const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, const struct device *dev); bool (*property_present)(const struct fwnode_handle *fwnode, diff --git a/include/linux/property.h b/include/linux/property.h index 357513a977e5..455b022fa612 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -50,6 +50,7 @@ int device_property_match_string(struct device *dev, const char *propname, const char *string); bool fwnode_device_is_available(const struct fwnode_handle *fwnode); +bool fwnode_device_is_reserved(const struct fwnode_handle *fwnode); bool fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname); int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode, From patchwork Fri Oct 22 02:00:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1544743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=DU7tY17F; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hb6zN3bcGz9sNH for ; Fri, 22 Oct 2021 13:01:52 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Hb6zN2WmXz3c7l for ; Fri, 22 Oct 2021 13:01:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=DU7tY17F; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=DU7tY17F; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Hb6y92NXtz2yHl for ; Fri, 22 Oct 2021 13:00:48 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 522BE98D; Thu, 21 Oct 2021 19:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1634868046; bh=a/XGFUg4+nH0ms1nAfRWPYozspJBU8EaTQ2O/BYzSYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DU7tY17FDr71jzgG2hHBqWK+HF30qVROqxkfhxnQd4PDWnwinchH8Eh1DnqGi11YN /VClEF+jolOai9moi6TK4ZrEIYJXVXlUP5HASzggFly1c8liUuj/4HOyA5ioxADpyJ cxLsXUTLz1Pyma9BF3JnMuTEhXLXcfmeksgLzRl4= From: Zev Weiss To: Frank Rowand , Greg Kroah-Hartman , Rob Herring Subject: [PATCH 3/5] of: property: add support for fwnode_device_is_reserved() Date: Thu, 21 Oct 2021 19:00:30 -0700 Message-Id: <20211022020032.26980-4-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211022020032.26980-1-zev@bewilderbeest.net> References: <20211022020032.26980-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Andrew Jeffery , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Jeremy Kerr Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This is just a simple pass-through to of_device_is_reserved(). Signed-off-by: Zev Weiss --- drivers/of/property.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index a3483484a5a2..67a8cb7ac462 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -872,6 +872,11 @@ static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode) return of_device_is_available(to_of_node(fwnode)); } +static bool of_fwnode_device_is_reserved(const struct fwnode_handle *fwnode) +{ + return of_device_is_reserved(to_of_node(fwnode)); +} + static bool of_fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname) { @@ -1458,6 +1463,7 @@ const struct fwnode_operations of_fwnode_ops = { .get = of_fwnode_get, .put = of_fwnode_put, .device_is_available = of_fwnode_device_is_available, + .device_is_reserved = of_fwnode_device_is_reserved, .device_get_match_data = of_fwnode_device_get_match_data, .property_present = of_fwnode_property_present, .property_read_int_array = of_fwnode_property_read_int_array, From patchwork Fri Oct 22 02:00:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1544744 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=d32Nc7aV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hb6zl6JLBz9sNH for ; Fri, 22 Oct 2021 13:02:11 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Hb6zl4l59z3bW9 for ; Fri, 22 Oct 2021 13:02:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=d32Nc7aV; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=d32Nc7aV; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Hb6yB1JMDz2ymg for ; Fri, 22 Oct 2021 13:00:49 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id AC68DB49; Thu, 21 Oct 2021 19:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1634868048; bh=7bg47D2PUr63KTjRLOr3QPGPVQLLJR5F+XwJqWsUVxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d32Nc7aVCto4w6Kfipr6ZiL8YdmnB5OWrXB2lhs04vNQPWK+6EyeHSmMros6UlQlu 3k3pSDbEuMoaMFI/V5OYe4FmeEtp3HfKObSMowHvvQjJ69rKZdSeBuAH9jlxfoxGYg mnUgrPoj2bSp1jM/i2Ypqq2xmph608ytcAVaee8w= From: Zev Weiss To: Frank Rowand , Greg Kroah-Hartman , Rob Herring Subject: [PATCH 4/5] driver core: inhibit automatic driver binding on reserved devices Date: Thu, 21 Oct 2021 19:00:31 -0700 Message-Id: <20211022020032.26980-5-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211022020032.26980-1-zev@bewilderbeest.net> References: <20211022020032.26980-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zev Weiss , "Rafael J. Wysocki" , Kirti Wankhede , Jeremy Kerr , Rajat Jain , Jianxiong Gao , Dave Jiang , kvm@vger.kernel.org, Saravana Kannan , Mauro Carvalho Chehab , openbmc@lists.ozlabs.org, devicetree@vger.kernel.org, Konrad Rzeszutek Wilk , Alex Williamson , Bhaskar Chowdhury , Thomas Gleixner , Andy Shevchenko , Andrew Jeffery , Cornelia Huck , linux-kernel@vger.kernel.org, Vinod Koul , dmaengine@vger.kernel.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Devices whose fwnodes are marked as reserved are instantiated, but will not have a driver bound to them unless userspace explicitly requests it by writing to a 'bind' sysfs file. This is to enable devices that may require special (userspace-mediated) preparation before a driver can safely probe them. Signed-off-by: Zev Weiss --- drivers/base/bus.c | 2 +- drivers/base/dd.c | 13 ++++++++----- drivers/dma/idxd/compat.c | 3 +-- drivers/vfio/mdev/mdev_core.c | 2 +- include/linux/device.h | 14 +++++++++++++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index bdc98c5713d5..8a30f9a02de0 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -211,7 +211,7 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, dev = bus_find_device_by_name(bus, NULL, buf); if (dev && driver_match_device(drv, dev)) { - err = device_driver_attach(drv, dev); + err = device_driver_attach(drv, dev, DRV_BIND_EXPLICIT); if (!err) { /* success */ err = count; diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 68ea1f949daa..ee64740a63d9 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -727,13 +728,14 @@ void wait_for_device_probe(void) } EXPORT_SYMBOL_GPL(wait_for_device_probe); -static int __driver_probe_device(struct device_driver *drv, struct device *dev) +static int __driver_probe_device(struct device_driver *drv, struct device *dev, u32 flags) { int ret = 0; if (dev->p->dead || !device_is_registered(dev)) return -ENODEV; - if (dev->driver) + if (dev->driver || + (fwnode_device_is_reserved(dev->fwnode) && !(flags & DRV_BIND_EXPLICIT))) return -EBUSY; dev->can_match = true; @@ -778,7 +780,7 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev) int ret; atomic_inc(&probe_count); - ret = __driver_probe_device(drv, dev); + ret = __driver_probe_device(drv, dev, DRV_BIND_DEFAULT); if (ret == -EPROBE_DEFER || ret == EPROBE_DEFER) { driver_deferred_probe_add(dev); @@ -1052,16 +1054,17 @@ static void __device_driver_unlock(struct device *dev, struct device *parent) * device_driver_attach - attach a specific driver to a specific device * @drv: Driver to attach * @dev: Device to attach it to + * @flags: Bitmask of DRV_BIND_* flags * * Manually attach driver to a device. Will acquire both @dev lock and * @dev->parent lock if needed. Returns 0 on success, -ERR on failure. */ -int device_driver_attach(struct device_driver *drv, struct device *dev) +int device_driver_attach(struct device_driver *drv, struct device *dev, u32 flags) { int ret; __device_driver_lock(dev, dev->parent); - ret = __driver_probe_device(drv, dev); + ret = __driver_probe_device(drv, dev, flags); __device_driver_unlock(dev, dev->parent); /* also return probe errors as normal negative errnos */ diff --git a/drivers/dma/idxd/compat.c b/drivers/dma/idxd/compat.c index 3df21615f888..51df38dea15a 100644 --- a/drivers/dma/idxd/compat.c +++ b/drivers/dma/idxd/compat.c @@ -7,7 +7,6 @@ #include #include "idxd.h" -extern int device_driver_attach(struct device_driver *drv, struct device *dev); extern void device_driver_detach(struct device *dev); #define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ @@ -56,7 +55,7 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, size_t cou if (!alt_drv) return -ENODEV; - rc = device_driver_attach(alt_drv, dev); + rc = device_driver_attach(alt_drv, dev, DRV_BIND_EXPLICIT); if (rc < 0) return rc; diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index b314101237fe..f42c6ec543c8 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -309,7 +309,7 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) if (!drv) drv = &vfio_mdev_driver; - ret = device_driver_attach(&drv->driver, &mdev->dev); + ret = device_driver_attach(&drv->driver, &mdev->dev, DRV_BIND_DEFAULT); if (ret) goto out_del; diff --git a/include/linux/device.h b/include/linux/device.h index e270cb740b9e..1ada1093799b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -876,12 +876,24 @@ static inline void *dev_get_platdata(const struct device *dev) return dev->platform_data; } +/* + * Driver-binding flags (for passing to device_driver_attach()) + * + * DRV_BIND_DEFAULT: a default, automatic bind, e.g. as a result of a device + * being added for which we already have a driver, or vice + * versa. + * DRV_BIND_EXPLICIT: an explicit, userspace-requested driver bind, e.g. as a + * result of a write to /sys/bus/.../drivers/.../bind + */ +#define DRV_BIND_DEFAULT 0 +#define DRV_BIND_EXPLICIT BIT(0) + /* * Manual binding of a device to driver. See drivers/base/bus.c * for information on use. */ int __must_check device_driver_attach(struct device_driver *drv, - struct device *dev); + struct device *dev, u32 flags); int __must_check device_bind_driver(struct device *dev); void device_release_driver(struct device *dev); int __must_check device_attach(struct device *dev); From patchwork Fri Oct 22 02:00:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1544747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=U2/S3A/W; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hb72314M2z9sNH for ; Fri, 22 Oct 2021 13:04:11 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Hb72248QCz3c90 for ; Fri, 22 Oct 2021 13:04:10 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=U2/S3A/W; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=U2/S3A/W; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Hb6yD4PDrz2y7X for ; Fri, 22 Oct 2021 13:00:52 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 86736B5D; Thu, 21 Oct 2021 19:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1634868048; bh=ywEBrdGbkyi0QJnFE8aQ/OJz+ZBKYfFbMIxjCGa0a6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2/S3A/W/JaKiShxEXetHUItCy/+sBkAcB5xLHm4tyjmabYHNOz9U8/A5M1LzWwIW ricK/uahG5gtjO5pOnXZZBD/XUJZsN3ZWiha2w8Ozz4XTx3UKbCziVpsgZPmxyR4yP I2mIzeFcQlU0iAilWPibes2OI83hj6YYmIpsRQxY= From: Zev Weiss To: Frank Rowand , Greg Kroah-Hartman , Rob Herring Subject: [PATCH 5/5] of: platform: instantiate reserved devices Date: Thu, 21 Oct 2021 19:00:32 -0700 Message-Id: <20211022020032.26980-6-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211022020032.26980-1-zev@bewilderbeest.net> References: <20211022020032.26980-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Andrew Jeffery , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Jeremy Kerr Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Devices with a "reserved" status will now be passed through to of_device_add() along with "okay" ones so that the driver core is aware of their existence and drivers can be explicitly bound to them when appropriate. Signed-off-by: Zev Weiss --- drivers/of/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 74afbb7a4f5e..060e1e9058c2 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -170,7 +170,7 @@ static struct platform_device *of_platform_device_create_pdata( { struct platform_device *dev; - if (!of_device_is_available(np) || + if ((!of_device_is_available(np) && !of_device_is_reserved(np)) || of_node_test_and_set_flag(np, OF_POPULATED)) return NULL;