From patchwork Thu Aug 25 16:40:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 600013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8037ECAA25 for ; Thu, 25 Aug 2022 16:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241032AbiHYQlH (ORCPT ); Thu, 25 Aug 2022 12:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233141AbiHYQlG (ORCPT ); Thu, 25 Aug 2022 12:41:06 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CB17BA175; Thu, 25 Aug 2022 09:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661445661; x=1692981661; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BCS0lNtsDfsx98IzhJrcwhFoiZhfU/dhPFeN+3Lsdl0=; b=CxLgUyNFlYcQTbllMDhZIYYY9XeDdw8XkfelQeXywU0paNuBxk0YLlHU 1gkC+c/LiSXpSrycw8TKTa4O/qzz1NGkaDRNmdpfd3G0qrv/P8etwRRQh 0bqu3/wOCJD+wV5F3BFuPKrPQC0gfgifNzXEtlf9RnIpKqQ6EryH0uaDO zY/eyXmX+GkRUNofCGuC+KeBd+SwFhOtweAHNRXaRcbnXKGZT/Rw3LNH1 0hG73qEglsqWB6Q/SsQcmouMbErH3Fl+3FPOVnG1Gq15+OMAiUIdevDM6 UpC43Gjp65w7KVMQMQBm/zMSuYCxo8vyjtXyJWTdoTU6zrS9lwo1UcK99 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="274689061" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="274689061" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 09:41:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="752554097" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Aug 2022 09:40:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8EBFB19D; Thu, 25 Aug 2022 19:41:13 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown Subject: [PATCH v1 1/5] ACPI: bus: Drop kernel doc annotation from acpi_bus_notify() Date: Thu, 25 Aug 2022 19:40:59 +0300 Message-Id: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The description for acpi_bus_notify() is quite far from what kernel doc expects. It complains about this: Function parameter or member 'handle' not described in 'acpi_bus_notify' Function parameter or member 'type' not described in 'acpi_bus_notify' Function parameter or member 'data' not described in 'acpi_bus_notify' Fix this by dropping kernel doc annotation. Signed-off-by: Andy Shevchenko --- drivers/acpi/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 6a1476cba3d3..8e87996607ec 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -456,7 +456,7 @@ static void acpi_bus_osc_negotiate_usb_control(void) Notification Handling -------------------------------------------------------------------------- */ -/** +/* * acpi_bus_notify * --------------- * Callback for all 'system-level' device notifications (values 0x00-0x7F). From patchwork Thu Aug 25 16:41:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 600591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95AD5ECAA28 for ; Thu, 25 Aug 2022 16:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241730AbiHYQlJ (ORCPT ); Thu, 25 Aug 2022 12:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238069AbiHYQlH (ORCPT ); Thu, 25 Aug 2022 12:41:07 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F941B99D8; Thu, 25 Aug 2022 09:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661445663; x=1692981663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bK5Pr9tx4aF8qD5Hm5yfT5c8GZSZbo0EmA54sQj8Dug=; b=O9nFwkyJR28qcCsHGsaFnXXfDxMoHFRZiuEw3h5ykINYQkWMqq+mAipx dXIdAwka1OsO0WcArBJ0Z63zmcRzmjzPixb88nHVoVtyVNyeacjzH4N2f gR6xWMMMnDcGWqDAeWHvbH25ubCOBerE4Xucpkut3kRA2Sfcn6G5utrxl c3k03n+6YymJoBL3QCOKZBZE+gMAWkAn/zIS2HENO/R/0ogoxP4V8Az// 3JfyxFtjMx0sP0LetNzKf2ccKRSkgeZ183Et10mngXUftnpdpHRLrsNWH R0IMLtgqZY5KVDrEnQQ3UD+YOkf2vrrR8v1ki9wQw6X724j6znWVChxpd w==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="380586964" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="380586964" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 09:41:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="786072443" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 25 Aug 2022 09:41:00 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 71E621C3; Thu, 25 Aug 2022 19:41:14 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown Subject: [PATCH v1 2/5] ACPI: bus: Refactor acpi_driver_match_device() for better readability Date: Thu, 25 Aug 2022 19:41:00 +0300 Message-Id: <20220825164103.27694-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> References: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org With temporary variables for OF and ACPI IDs, it's easier to read the code. No functional change intended. Signed-off-by: Andy Shevchenko --- drivers/acpi/bus.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 8e87996607ec..c4d63c594d68 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -948,14 +948,13 @@ EXPORT_SYMBOL(acpi_match_device_ids); bool acpi_driver_match_device(struct device *dev, const struct device_driver *drv) { - if (!drv->acpi_match_table) - return acpi_of_match_device(ACPI_COMPANION(dev), - drv->of_match_table, - NULL); - - return __acpi_match_device(acpi_companion_match(dev), - drv->acpi_match_table, drv->of_match_table, - NULL, NULL); + const struct acpi_device_id *acpi_ids = drv->acpi_match_table; + const struct of_device_id *of_ids = drv->of_match_table; + + if (!acpi_ids) + return acpi_of_match_device(ACPI_COMPANION(dev), of_ids, NULL); + + return __acpi_match_device(acpi_companion_match(dev), acpi_ids, of_ids, NULL, NULL); } EXPORT_SYMBOL_GPL(acpi_driver_match_device); From patchwork Thu Aug 25 16:41:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 600592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 274CAECAA24 for ; Thu, 25 Aug 2022 16:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236708AbiHYQlI (ORCPT ); Thu, 25 Aug 2022 12:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234556AbiHYQlH (ORCPT ); Thu, 25 Aug 2022 12:41:07 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D9FBA9C0; Thu, 25 Aug 2022 09:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661445662; x=1692981662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6L5YW6wVIrpaazRx3sSRrkRPhSy6FbkOX5mt46QUY8A=; b=QozEPdJvqeNiEkKxxbQ9SSQp4wiggD/7NpJ0MjUzopx77nJffSPvvbwD 5I7NFljkNBaRWNg/pkcCZ2QDNaYl0PBoZCvdTTeXS6zPE3+89DmokodEc neoQSxn2MTyC4s8vsKql0eQv+brRTUFUGjeM/4QR7xOpXnL1b7hmfUytT n6v5QXDTBRZ3R1KTu0CEx5KBKovcjh4wSkbZpd+fqZsSh5wbBOPeWuXa1 ldEgX6hmO7zddVrDY1121NlxRPjm1YqcweHDbdPzizOn49NcpFJXgFGeR k6eHBkw2qaPfTPfozZ7azdIqnByz3atxdlFhSnGdc9oZkgFAL+nSNZ5NV g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="274689067" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="274689067" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 09:41:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="855701164" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 25 Aug 2022 09:41:00 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D2A5F238; Thu, 25 Aug 2022 19:41:14 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown Subject: [PATCH v1 3/5] ACPI: bus: Refactor acpi_bus_register_driver() to get rid of 'ret' Date: Thu, 25 Aug 2022 19:41:01 +0300 Message-Id: <20220825164103.27694-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> References: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org There is no need to have 'ret' variable in acpi_bus_register_driver(). Refactor it accordingly. Signed-off-by: Andy Shevchenko --- drivers/acpi/bus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index c4d63c594d68..607e664b7976 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -972,16 +972,14 @@ EXPORT_SYMBOL_GPL(acpi_driver_match_device); */ int acpi_bus_register_driver(struct acpi_driver *driver) { - int ret; - if (acpi_disabled) return -ENODEV; + driver->drv.name = driver->name; driver->drv.bus = &acpi_bus_type; driver->drv.owner = driver->owner; - ret = driver_register(&driver->drv); - return ret; + return driver_register(&driver->drv); } EXPORT_SYMBOL(acpi_bus_register_driver); From patchwork Thu Aug 25 16:41:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 600012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CEBBECAA27 for ; Thu, 25 Aug 2022 16:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239769AbiHYQlI (ORCPT ); Thu, 25 Aug 2022 12:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237937AbiHYQlH (ORCPT ); Thu, 25 Aug 2022 12:41:07 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7C6FB9F85; Thu, 25 Aug 2022 09:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661445662; x=1692981662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2ipgmuE2YNebiTYyr6pNxvrRl4wbsFK6T5Vp+SAGbN4=; b=QjX5J3l7+u+bljJOJJuezvzgSlPWdgMvTO4+csQfNn7XFKsfz9f/FJe0 FtS7Vc/U4rTzefRjY8R+Srk56N3sZgOjcAUGoKzCvTqJknApCF45LJkFw D5W25sJAk5Pc1PC3k7+UdwGvT0tLsGbiQxjqm6TgojW2iEbIISv/YzZT/ yI1NcHhwQVdHocZKiuzri4meuPD7jlxZhIJfsrtGYfWiqrMv6zvIrVe+a okRDiY9rl4oQzqyqf+JC557HDzHJcVu0HyzrOb/AbPpFhwzCP+S8lTMhd aMefOIvYPydyUS2yqLhM7chb7UG7e93UQnXD+HCXTuXXBowcqeXEN6hEv A==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="274046559" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="274046559" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 09:41:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="938403134" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 25 Aug 2022 09:41:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4231C2E7; Thu, 25 Aug 2022 19:41:15 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown Subject: [PATCH v1 4/5] ACPI: bus: Move bus type operations upper in the code Date: Thu, 25 Aug 2022 19:41:02 +0300 Message-Id: <20220825164103.27694-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> References: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Move ACPI bus type operations upper in the code, it may be used later by ACPI device matching code. No functional change intended. While at it, provide dev_is_acpi() macro helper as it's done for some other bus types. Signed-off-by: Andy Shevchenko --- drivers/acpi/bus.c | 250 +++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 124 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 607e664b7976..3c0f2d050d47 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -647,6 +647,132 @@ static int __init acpi_setup_sb_notify_handler(void) return 0; } +/* -------------------------------------------------------------------------- + ACPI Bus operations + -------------------------------------------------------------------------- */ + +static int acpi_bus_match(struct device *dev, struct device_driver *drv) +{ + struct acpi_device *acpi_dev = to_acpi_device(dev); + struct acpi_driver *acpi_drv = to_acpi_driver(drv); + + return acpi_dev->flags.match_driver + && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); +} + +static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + return __acpi_device_uevent_modalias(to_acpi_device(dev), env); +} + +static int acpi_device_probe(struct device *dev) +{ + struct acpi_device *acpi_dev = to_acpi_device(dev); + struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); + int ret; + + if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev)) + return -EINVAL; + + if (!acpi_drv->ops.add) + return -ENOSYS; + + ret = acpi_drv->ops.add(acpi_dev); + if (ret) + return ret; + + pr_debug("Driver [%s] successfully bound to device [%s]\n", + acpi_drv->name, acpi_dev->pnp.bus_id); + + if (acpi_drv->ops.notify) { + ret = acpi_device_install_notify_handler(acpi_dev); + if (ret) { + if (acpi_drv->ops.remove) + acpi_drv->ops.remove(acpi_dev); + + acpi_dev->driver_data = NULL; + return ret; + } + } + + pr_debug("Found driver [%s] for device [%s]\n", acpi_drv->name, + acpi_dev->pnp.bus_id); + + get_device(dev); + return 0; +} + +static void acpi_device_remove(struct device *dev) +{ + struct acpi_device *acpi_dev = to_acpi_device(dev); + struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); + + if (acpi_drv->ops.notify) + acpi_device_remove_notify_handler(acpi_dev); + + if (acpi_drv->ops.remove) + acpi_drv->ops.remove(acpi_dev); + + acpi_dev->driver_data = NULL; + + put_device(dev); +} + +struct bus_type acpi_bus_type = { + .name = "acpi", + .match = acpi_bus_match, + .probe = acpi_device_probe, + .remove = acpi_device_remove, + .uevent = acpi_device_uevent, +}; + +#define dev_is_acpi(dev) ((dev)->bus == &acpi_bus_type) + +int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data) +{ + return bus_for_each_dev(&acpi_bus_type, NULL, data, fn); +} +EXPORT_SYMBOL_GPL(acpi_bus_for_each_dev); + +struct acpi_dev_walk_context { + int (*fn)(struct acpi_device *, void *); + void *data; +}; + +static int acpi_dev_for_one_check(struct device *dev, void *context) +{ + struct acpi_dev_walk_context *adwc = context; + + if (!dev_is_acpi(dev)) + return 0; + + return adwc->fn(to_acpi_device(dev), adwc->data); +} +EXPORT_SYMBOL_GPL(acpi_dev_for_each_child); + +int acpi_dev_for_each_child(struct acpi_device *adev, + int (*fn)(struct acpi_device *, void *), void *data) +{ + struct acpi_dev_walk_context adwc = { + .fn = fn, + .data = data, + }; + + return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check); +} + +int acpi_dev_for_each_child_reverse(struct acpi_device *adev, + int (*fn)(struct acpi_device *, void *), + void *data) +{ + struct acpi_dev_walk_context adwc = { + .fn = fn, + .data = data, + }; + + return device_for_each_child_reverse(&adev->dev, &adwc, acpi_dev_for_one_check); +} + /* -------------------------------------------------------------------------- Device Matching -------------------------------------------------------------------------- */ @@ -998,130 +1124,6 @@ void acpi_bus_unregister_driver(struct acpi_driver *driver) EXPORT_SYMBOL(acpi_bus_unregister_driver); -/* -------------------------------------------------------------------------- - ACPI Bus operations - -------------------------------------------------------------------------- */ - -static int acpi_bus_match(struct device *dev, struct device_driver *drv) -{ - struct acpi_device *acpi_dev = to_acpi_device(dev); - struct acpi_driver *acpi_drv = to_acpi_driver(drv); - - return acpi_dev->flags.match_driver - && !acpi_match_device_ids(acpi_dev, acpi_drv->ids); -} - -static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) -{ - return __acpi_device_uevent_modalias(to_acpi_device(dev), env); -} - -static int acpi_device_probe(struct device *dev) -{ - struct acpi_device *acpi_dev = to_acpi_device(dev); - struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); - int ret; - - if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev)) - return -EINVAL; - - if (!acpi_drv->ops.add) - return -ENOSYS; - - ret = acpi_drv->ops.add(acpi_dev); - if (ret) - return ret; - - pr_debug("Driver [%s] successfully bound to device [%s]\n", - acpi_drv->name, acpi_dev->pnp.bus_id); - - if (acpi_drv->ops.notify) { - ret = acpi_device_install_notify_handler(acpi_dev); - if (ret) { - if (acpi_drv->ops.remove) - acpi_drv->ops.remove(acpi_dev); - - acpi_dev->driver_data = NULL; - return ret; - } - } - - pr_debug("Found driver [%s] for device [%s]\n", acpi_drv->name, - acpi_dev->pnp.bus_id); - - get_device(dev); - return 0; -} - -static void acpi_device_remove(struct device *dev) -{ - struct acpi_device *acpi_dev = to_acpi_device(dev); - struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); - - if (acpi_drv->ops.notify) - acpi_device_remove_notify_handler(acpi_dev); - - if (acpi_drv->ops.remove) - acpi_drv->ops.remove(acpi_dev); - - acpi_dev->driver_data = NULL; - - put_device(dev); -} - -struct bus_type acpi_bus_type = { - .name = "acpi", - .match = acpi_bus_match, - .probe = acpi_device_probe, - .remove = acpi_device_remove, - .uevent = acpi_device_uevent, -}; - -int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data) -{ - return bus_for_each_dev(&acpi_bus_type, NULL, data, fn); -} -EXPORT_SYMBOL_GPL(acpi_bus_for_each_dev); - -struct acpi_dev_walk_context { - int (*fn)(struct acpi_device *, void *); - void *data; -}; - -static int acpi_dev_for_one_check(struct device *dev, void *context) -{ - struct acpi_dev_walk_context *adwc = context; - - if (dev->bus != &acpi_bus_type) - return 0; - - return adwc->fn(to_acpi_device(dev), adwc->data); -} -EXPORT_SYMBOL_GPL(acpi_dev_for_each_child); - -int acpi_dev_for_each_child(struct acpi_device *adev, - int (*fn)(struct acpi_device *, void *), void *data) -{ - struct acpi_dev_walk_context adwc = { - .fn = fn, - .data = data, - }; - - return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check); -} - -int acpi_dev_for_each_child_reverse(struct acpi_device *adev, - int (*fn)(struct acpi_device *, void *), - void *data) -{ - struct acpi_dev_walk_context adwc = { - .fn = fn, - .data = data, - }; - - return device_for_each_child_reverse(&adev->dev, &adwc, acpi_dev_for_one_check); -} - /* -------------------------------------------------------------------------- Initialization/Cleanup -------------------------------------------------------------------------- */ From patchwork Thu Aug 25 16:41:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 600011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1252ECAA25 for ; Thu, 25 Aug 2022 16:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241610AbiHYQlK (ORCPT ); Thu, 25 Aug 2022 12:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240039AbiHYQlH (ORCPT ); Thu, 25 Aug 2022 12:41:07 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6014B9FB0; Thu, 25 Aug 2022 09:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661445663; x=1692981663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MwVIs/zJ7mRuBvOdPKfAl5h+2iG+pF9LW6lI3yel2kw=; b=EIxOwHzvMukt2zpAvGifDX2ZUEWHeYHilLhvBMVwqMZxxOMWa2jaEPdc bRwFuMzlINlr2cnT47M58yb3bZc4GtnHOexlAYdpBcvhuSAqB8gddTgEq wtnRrAHZ4/i/5FifklEVVHmetAck3w5bEUuau/Guq2ZO/eTFGLF25Fd10 s739vn+nJhCSwor2gLsv9cmESZfpzf9BIpPzx6/jQF02QCtEIojrW8Bsq /Flv2Wfeu9s3Seve1ZiLjzDQkYOUdphPzF4L1iyNXR4z/Ripg1aLQxRV3 8fL4jO23QQW/Ff0SFscXG4rtnbugULywDE77f1ezcECmyYYO5TwPSz7G5 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="356013486" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="356013486" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 09:41:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="613228127" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 25 Aug 2022 09:41:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9BD4B49F; Thu, 25 Aug 2022 19:41:15 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown Subject: [PATCH v1 5/5] ACPI: bus: Use the matching table, if ACPI driver has it Date: Thu, 25 Aug 2022 19:41:03 +0300 Message-Id: <20220825164103.27694-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> References: <20220825164103.27694-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In case we have an ACPI driver, check its ID table for matching, This allows to use some generic device property APIs in such drivers. Signed-off-by: Andy Shevchenko --- drivers/acpi/bus.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 3c0f2d050d47..17c98e826bde 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1049,14 +1049,30 @@ static const void *acpi_of_device_get_match_data(const struct device *dev) return match->data; } +static const struct acpi_device_id *acpi_device_get_ids(const struct device *dev) +{ + if (dev->driver->acpi_match_table) + return dev->driver->acpi_match_table; + + if (dev_is_acpi(dev)) { + struct acpi_driver *drv = to_acpi_driver(dev->driver); + + if (drv->ids) + return drv->ids; + } + + return NULL; +} + const void *acpi_device_get_match_data(const struct device *dev) { + const struct acpi_device_id *ids = acpi_device_get_ids(dev); const struct acpi_device_id *match; - if (!dev->driver->acpi_match_table) + if (!ids) return acpi_of_device_get_match_data(dev); - match = acpi_match_device(dev->driver->acpi_match_table, dev); + match = acpi_match_device(ids, dev); if (!match) return NULL;