From patchwork Sun Nov 17 16:36:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 3194261 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7D7D89F345 for ; Sun, 17 Nov 2013 16:25:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94F9820602 for ; Sun, 17 Nov 2013 16:25:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A03002047C for ; Sun, 17 Nov 2013 16:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754437Ab3KQQZz (ORCPT ); Sun, 17 Nov 2013 11:25:55 -0500 Received: from v094114.home.net.pl ([79.96.170.134]:50801 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752420Ab3KQQZs (ORCPT ); Sun, 17 Nov 2013 11:25:48 -0500 Received: from afeb192.neoplus.adsl.tpnet.pl [95.49.105.192] (HELO vostro.rjw.lan) by serwer1319399.home.pl [79.96.170.134] with SMTP (IdeaSmtpServer v0.80) id 611c60e995a9f8b1; Sun, 17 Nov 2013 17:25:47 +0100 From: "Rafael J. Wysocki" To: ACPI Devel Maling List Cc: Greg Kroah-Hartman , LKML , Linux PCI , "Moore, Robert" , Toshi Kani , Yinghai Lu , Zhang Rui , Bjorn Helgaas , Mika Westerberg , Aaron Lu , Lv Zheng Subject: [PATCH 8/10] ACPI / hotplug: Rework generic code to handle suprise removals Date: Sun, 17 Nov 2013 17:36:42 +0100 Message-ID: <3525698.21F2z08v1h@vostro.rjw.lan> User-Agent: KMail/4.10.5 (Linux/3.12.0-rc6+; KDE/4.10.5; x86_64; ; ) In-Reply-To: <1421028.Rsfpmhnym3@vostro.rjw.lan> References: <1421028.Rsfpmhnym3@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki The generic ACPI hotplug code used for several types of device doesn't handle surprise removals, mostly because those devices currently cannot be removed by surprise in the majority of systems. However, surprise removals should be handled by that code as well as surprise additions of devices, so make it do that. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 85 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 26 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-pm/drivers/acpi/scan.c =================================================================== --- linux-pm.orig/drivers/acpi/scan.c +++ linux-pm/drivers/acpi/scan.c @@ -276,18 +276,72 @@ static int acpi_scan_hot_remove(struct a return 0; } +static int acpi_scan_device_not_present(struct acpi_device *adev) +{ + if (!acpi_device_enumerated(adev)) { + dev_warn(&adev->dev, "Still not present\n"); + return -EALREADY; + } + acpi_bus_trim(adev); + return 0; +} + static int acpi_scan_device_check(struct acpi_device *adev) { int error; + acpi_bus_get_status(adev); + if (adev->status.present || adev->status.functional) { + /* + * This function is only called for device objects for which + * matching scan handlers exist. The only situation in which + * the scan handler is not attached to this device object yet + * is when the device has just appeared (either it wasn't + * present at all before or it was removed and then added + * again). + */ + if (adev->handler) { + dev_warn(&adev->dev, "Already enumerated\n"); + return -EALREADY; + } + error = acpi_bus_scan(adev->handle); + if (error) { + dev_warn(&adev->dev, "Namespace scan failure\n"); + return error; + } + if (!adev->handler) { + dev_warn(&adev->dev, "Enumeration failure\n"); + error = -ENODEV; + } + } else { + error = acpi_scan_device_not_present(adev); + } + return error; +} + +static int acpi_scan_bus_check(struct acpi_device *adev) +{ + struct acpi_scan_handler *handler = adev->handler; + struct acpi_device *child; + int error; + + acpi_bus_get_status(adev); + if (!(adev->status.present || adev->status.functional)) { + acpi_scan_device_not_present(adev); + return 0; + } + if (handler && handler->hotplug.scan_dependent) + return handler->hotplug.scan_dependent(adev); + error = acpi_bus_scan(adev->handle); if (error) { dev_warn(&adev->dev, "Namespace scan failure\n"); return error; } - if (!adev->handler) { - dev_warn(&adev->dev, "Enumeration failure\n"); - return -ENODEV; + list_for_each_entry(child, &adev->children, node) { + error = acpi_scan_bus_check(child); + if (error) + return error; } return 0; } @@ -296,7 +350,6 @@ static void acpi_device_hotplug(void *da { u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; struct acpi_device *adev = data; - struct acpi_scan_handler *handler; int error; lock_device_hotplug(); @@ -310,32 +363,12 @@ static void acpi_device_hotplug(void *da if (adev->handle == INVALID_ACPI_HANDLE) goto out; - handler = adev->handler; - switch (src) { case ACPI_NOTIFY_BUS_CHECK: - if (handler) { - error = handler->hotplug.scan_dependent ? - handler->hotplug.scan_dependent(adev) : - acpi_bus_scan(adev->handle); - } else { - error = acpi_scan_device_check(adev); - } + error = acpi_scan_bus_check(adev); break; case ACPI_NOTIFY_DEVICE_CHECK: - /* - * This code is only run for device objects for which matching - * scan handlers exist. The only situation in which the scan - * handler is not attached to this device object yet is when the - * device has just appeared (either it wasn't present at all - * before or it was removed and then added again). - */ - if (adev->handler) { - dev_warn(&adev->dev, "Already enumerated\n"); - error = -EBUSY; - } else { - error = acpi_scan_device_check(adev); - } + error = acpi_scan_device_check(adev); break; case ACPI_NOTIFY_EJECT_REQUEST: case ACPI_OST_EC_OSPM_EJECT: