From patchwork Sat Oct 6 15:27:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1558011 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 38D60DF238 for ; Sat, 6 Oct 2012 15:31:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752916Ab2JFPaQ (ORCPT ); Sat, 6 Oct 2012 11:30:16 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:63060 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751572Ab2JFPaN (ORCPT ); Sat, 6 Oct 2012 11:30:13 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so2814954pbb.19 for ; Sat, 06 Oct 2012 08:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=tJRKBzut8B4KGWDvBZ+rsyCHTJqhjs6YJo/Qiu/MWtQ=; b=lnZJCpQ4VCIoybMV7arwEod/8bsqbZ7EHtE4sCoVJfx1gjEGEyoWLHfq7FxSz4WQLp YDK9DI7RCu9lxcux6FLF/E2JZczmE2r3bG4WMmEmpmuG4+4B5hU+3R8adNavJa+Dxk8s Kb5Lo+NtcAI4DQKA95rnGRezczRFfXW6ibc7pNwHwqeR4ilPFkzBCXuAHazpsAVDk4jC Q3i1g5xAGijplMp6/LQjt5Eo2E2bxqtWU+hM7xleQmmWspfY6+J4p1Vsdu0FWDoQNN3y KKO473ExTopO/IND/pCiG+hS7Q2FqeTE1XJHgWZ/lSfEZZQv2uVl93kaPsNkn8dETdqr U22w== Received: by 10.68.225.34 with SMTP id rh2mr39380408pbc.78.1349537413304; Sat, 06 Oct 2012 08:30:13 -0700 (PDT) Received: from localhost.localdomain ([221.221.24.247]) by mx.google.com with ESMTPS id vz8sm7785292pbc.63.2012.10.06.08.29.58 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Oct 2012 08:30:12 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Yasuaki Ishimatsu , Kenji Kaneshige , Wen Congyang , Tang Chen , Taku Izumi Cc: Hanjun Guo , Yijing Wang , Gong Chen , Jiang Liu , Tony Luck , Huang Ying , Bob Moore , Len Brown , "Srivatsa S . Bhat" , Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Subject: [RFC PATCH v3 04/28] ACPIHP: implement a fake ACPI system device hotplug slot enumerator Date: Sat, 6 Oct 2012 23:27:12 +0800 Message-Id: <1349537256-21670-5-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1349537256-21670-1-git-send-email-jiang.liu@huawei.com> References: <1349537256-21670-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch implements a fake ACPI system device hotplug slot enumerator, which could be used to test and verify hotplug logic on platforms with hardware hotplug capabilities. The fake slot enumerator will be enabled by passing module parameter "fake_slot=value". The encoding of "value" is: 0x1: fake ACPI CONTAINER device as hotplug slot 0x2: fake ACPI memory device as hotplug slot 0x4: fake ACPI Processor object or Processor device as hotplug slot 0x8: fake ACPI PCI host bridge device as hotplug slot. Signed-off-by: Jiang Liu --- drivers/acpi/Kconfig | 9 ++ drivers/acpi/hotplug/Makefile | 1 + drivers/acpi/hotplug/acpihp.h | 3 + drivers/acpi/hotplug/slot.c | 3 + drivers/acpi/hotplug/slot_fake.c | 177 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 drivers/acpi/hotplug/slot_fake.c diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 915a25e..5a5a3e5 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -348,6 +348,15 @@ config ACPI_HOTPLUG_SLOT To compile this driver as a module, choose M here: the module will be called acpihp_slot. +config ACPI_HOTPLUG_SLOT_FAKE + bool "Fake Hotplug Slot Enumerator" + depends on ACPI_HOTPLUG_SLOT + default y + help + Enable the fake ACPI system device hotplug slot enumerator, which + could be used to test hotplug functionalities on hardware platforms + with out system device hotplug capabilities. + config ACPI_CONTAINER tristate "Container and Module Devices (EXPERIMENTAL)" depends on EXPERIMENTAL diff --git a/drivers/acpi/hotplug/Makefile b/drivers/acpi/hotplug/Makefile index 5420ae7..c19b350 100644 --- a/drivers/acpi/hotplug/Makefile +++ b/drivers/acpi/hotplug/Makefile @@ -8,3 +8,4 @@ acpihp-y = core.o obj-$(CONFIG_ACPI_HOTPLUG_SLOT) += acpihp_slot.o acpihp_slot-y = slot.o acpihp_slot-y += slot_ej0.o +acpihp_slot-$(CONFIG_ACPI_HOTPLUG_SLOT_FAKE) += slot_fake.o diff --git a/drivers/acpi/hotplug/acpihp.h b/drivers/acpi/hotplug/acpihp.h index 278c8c2..7c49eab 100644 --- a/drivers/acpi/hotplug/acpihp.h +++ b/drivers/acpi/hotplug/acpihp.h @@ -29,5 +29,8 @@ extern struct acpi_device *acpi_root; extern struct acpihp_slot_ops acpihp_slot_ej0; +#ifdef CONFIG_ACPI_HOTPLUG_SLOT_FAKE +extern struct acpihp_slot_ops acpihp_slot_fake; +#endif #endif diff --git a/drivers/acpi/hotplug/slot.c b/drivers/acpi/hotplug/slot.c index 8fdae61..38f39dc 100644 --- a/drivers/acpi/hotplug/slot.c +++ b/drivers/acpi/hotplug/slot.c @@ -44,6 +44,9 @@ static struct acpihp_slot_ops *slot_ops_curr; */ static struct acpihp_slot_ops *slot_ops_array[] = { &acpihp_slot_ej0, +#ifdef CONFIG_ACPI_HOTPLUG_SLOT_FAKE + &acpihp_slot_fake, +#endif NULL }; diff --git a/drivers/acpi/hotplug/slot_fake.c b/drivers/acpi/hotplug/slot_fake.c new file mode 100644 index 0000000..512e09b --- /dev/null +++ b/drivers/acpi/hotplug/slot_fake.c @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2012 Huawei Tech. Co., Ltd. + * Copyright (C) 2012 Jiang Liu + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +#include +#include +#include +#include "acpihp.h" + +struct acpihp_slot_fake_data { + bool enabled; +}; + +/* + * Encoding of the fake_slot parameter: + * 0x1: fake ACPI CONTAINER device as hotplug slot + * 0x2: fake ACPI memory device as hotplug slot + * 0x4: fake ACPI Processor object or Processor device as hotplug slot + * 0x8: fake ACPI PCI host bridge device as hotplug slot. + * The above encoding must be kept in consistence with definition of + * 'enum acpihp_dev_type'. + */ +int acpihp_fake_slot; +module_param_named(fake_slot, acpihp_fake_slot, int, S_IRUGO); +MODULE_PARM_DESC(fake_slot, "fake ACPI hotplug slots, 0x1 for CONTAINER, 0x2 for memory, 0x4 for CPU, 0x8 for PCI host bridge."); + +static acpi_status acpihp_slot_fake_init(void) +{ + return acpihp_fake_slot ? AE_OK : AE_ERROR; +} + +static acpi_status +acpihp_slot_fake_check(acpi_handle handle, u32 lvl, void *context, void **rv) +{ + int *valid = (int *)rv; + enum acpihp_dev_type type; + + if (!acpihp_dev_get_type(handle, &type)) { + switch (type) { + case ACPIHP_DEV_TYPE_CPU: + case ACPIHP_DEV_TYPE_MEM: + case ACPIHP_DEV_TYPE_HOST_BRIDGE: + *valid = 1; + return AE_CTRL_TERMINATE; + default: + break; + } + } + + return AE_OK; +} + +static acpi_status acpihp_slot_fake_capable(acpi_handle handle) +{ + int valid = 0; + acpi_status rc; + unsigned long long sta; + enum acpihp_dev_type type; + + /* Only care about CPU, memory, PCI host bridge and CONTAINER */ + if (acpihp_dev_get_type(handle, &type)) + return AE_ERROR; + if (type == ACPIHP_DEV_TYPE_CPU || type == ACPIHP_DEV_TYPE_MEM || + type == ACPIHP_DEV_TYPE_HOST_BRIDGE) { + if (acpihp_fake_slot & (1 << (type - 1))) + valid = 1; + } else if (type == ACPIHP_DEV_TYPE_CONTAINER && + acpihp_fake_slot & (1 << (type - 1))) { + acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, + ACPI_UINT32_MAX, acpihp_slot_fake_check, + NULL, NULL, (void **)&valid); + acpi_walk_namespace(ACPI_TYPE_PROCESSOR, handle, + ACPI_UINT32_MAX, acpihp_slot_fake_check, + NULL, NULL, (void **)&valid); + } + if (valid == 0) + return AE_ERROR; + + /* Check whether device is present and enabled. */ + rc = acpi_evaluate_integer(handle, "_STA", NULL, &sta); + if (rc == AE_NOT_FOUND) + sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED; + else if (ACPI_FAILURE(rc)) + sta = 0; + else if (sta & ACPI_STA_DEVICE_FUNCTIONING) + sta |= ACPI_STA_DEVICE_ENABLED; + if (!(sta & ACPI_STA_DEVICE_PRESENT) || + !(sta & ACPI_STA_DEVICE_ENABLED)) + return AE_ERROR; + + return AE_OK; +} + +static acpi_status acpihp_slot_fake_create(struct acpihp_slot *slot) +{ + struct acpihp_slot_fake_data *data; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return AE_ERROR; + + data->enabled = true; + slot->slot_data = data; + slot->capabilities = ACPIHP_SLOT_CAP_ONLINE | ACPIHP_SLOT_CAP_OFFLINE; + + return AE_OK; +} + +static void acpihp_slot_fake_destroy(struct acpihp_slot *slot) +{ + struct acpihp_slot_fake_data *data = slot->slot_data; + + slot->slot_data = NULL; + kfree(data); +} + +static acpi_status +acpihp_slot_fake_get_status(struct acpihp_slot *slot, u64 *status) +{ + struct acpihp_slot_fake_data *data = slot->slot_data; + + if (data->enabled) + *status = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | + ACPI_STA_DEVICE_FUNCTIONING; + else + *status = ACPI_STA_DEVICE_PRESENT; + + return AE_OK; +} + +static acpi_status acpihp_slot_fake_poweron(struct acpihp_slot *slot) +{ + struct acpihp_slot_fake_data *data = slot->slot_data; + + data->enabled = true; + + return AE_OK; +} + +static acpi_status acpihp_slot_fake_poweroff(struct acpihp_slot *slot) +{ + struct acpihp_slot_fake_data *data = slot->slot_data; + + data->enabled = false; + + return AE_OK; +} + +struct acpihp_slot_ops acpihp_slot_fake = { + .owner = THIS_MODULE, + .desc = "Fake ACPI System Device Hotplug Slots for Testing", + .init = acpihp_slot_fake_init, + .check = acpihp_slot_fake_capable, + .create = acpihp_slot_fake_create, + .destroy = acpihp_slot_fake_destroy, + .poweron = acpihp_slot_fake_poweron, + .poweroff = acpihp_slot_fake_poweroff, + .get_status = acpihp_slot_fake_get_status, +};