From patchwork Fri Jan 11 22:40:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 1968141 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2F3D5DF2A2 for ; Fri, 11 Jan 2013 22:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755883Ab3AKWpv (ORCPT ); Fri, 11 Jan 2013 17:45:51 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:22825 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755968Ab3AKWlO (ORCPT ); Fri, 11 Jan 2013 17:41:14 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id r0BMf6Lb028210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Jan 2013 22:41:07 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r0BMf6Ws011668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Jan 2013 22:41:06 GMT Received: from abhmt117.oracle.com (abhmt117.oracle.com [141.146.116.69]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r0BMf5gp029561; Fri, 11 Jan 2013 16:41:05 -0600 Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Jan 2013 14:41:05 -0800 From: Yinghai Lu To: Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown , Taku Izumi , Jiang Liu Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Yinghai Lu Subject: [PATCH v8 09/22] PCI, ACPI: Add pci_root_hp hot removal notification support. Date: Fri, 11 Jan 2013 14:40:36 -0800 Message-Id: <1357944049-29620-10-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357944049-29620-1-git-send-email-yinghai@kernel.org> References: <1357944049-29620-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add missing hot_remove support for root device. How to test it? Find out root bus number to acpi root name mapping from dmesg or /sys echo "\_SB.PCIB 3" > /sys/kernel/debug/acpi/sci_notify to remove root bus -v2: separate stop and remove, so it will be safe for comingi acpi_pci_bind_notify() changes. Signed-off-by: Yinghai Lu Cc: Len Brown Cc: linux-acpi@vger.kernel.org --- drivers/acpi/pci_root.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 5c1f462c..5ae36d8 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -740,6 +740,12 @@ static void add_acpi_root_bridge(acpi_handle handle) list_add(&bridge->list, &acpi_root_bridge_list); } +static void remove_acpi_root_bridge(struct acpi_root_bridge *bridge) +{ + list_del(&bridge->list); + kfree(bridge); +} + struct acpi_root_hp_work { struct work_struct work; acpi_handle handle; @@ -800,6 +806,61 @@ static void handle_root_bridge_insertion(acpi_handle handle) printk(KERN_ERR "cannot add bridge to acpi list\n"); } +static int acpi_root_evaluate_object(acpi_handle handle, char *cmd, int val) +{ + acpi_status status; + struct acpi_object_list arg_list; + union acpi_object arg; + + arg_list.count = 1; + arg_list.pointer = &arg; + arg.type = ACPI_TYPE_INTEGER; + arg.integer.value = val; + + status = acpi_evaluate_object(handle, cmd, &arg_list, NULL); + if (ACPI_FAILURE(status)) { + pr_warn("%s: %s to %d failed\n", + __func__, cmd, val); + return -1; + } + + return 0; +} + +static void handle_root_bridge_removal(acpi_handle handle, + struct acpi_root_bridge *bridge) +{ + u32 flags = 0; + struct acpi_device *device; + + if (bridge) { + flags = bridge->flags; + remove_acpi_root_bridge(bridge); + } + + if (!acpi_bus_get_device(handle, &device)) { + int ret_val; + + /* remove pci devices at first */ + ret_val = acpi_bus_trim(device, 0); + printk(KERN_DEBUG "acpi_bus_trim stop return %x\n", ret_val); + + /* remove acpi devices */ + ret_val = acpi_bus_trim(device, 1); + printk(KERN_DEBUG "acpi_bus_trim remove return %x\n", ret_val); + } + + if (flags & ROOT_BRIDGE_HAS_PS3) { + acpi_status status; + + status = acpi_evaluate_object(handle, "_PS3", NULL, NULL); + if (ACPI_FAILURE(status)) + pr_warn("%s: _PS3 failed\n", __func__); + } + if (flags & ROOT_BRIDGE_HAS_EJ0) + acpi_root_evaluate_object(handle, "_EJ0", 1); +} + static void _handle_hotplug_event_root(struct work_struct *work) { struct acpi_root_bridge *bridge; @@ -840,6 +901,12 @@ static void _handle_hotplug_event_root(struct work_struct *work) } break; + case ACPI_NOTIFY_EJECT_REQUEST: + /* request device eject */ + printk(KERN_DEBUG "%s: Device eject notify on %s\n", __func__, + objname); + handle_root_bridge_removal(handle, bridge); + break; default: printk(KERN_WARNING "notify_handler: unknown event type 0x%x for %s\n", type, objname);