From patchwork Mon Oct 14 09:10:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 3034991 Return-Path: X-Original-To: patchwork-linux-acpi@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 496A69F2B6 for ; Mon, 14 Oct 2013 09:10:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E72E202BE for ; Mon, 14 Oct 2013 09:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC4A720253 for ; Mon, 14 Oct 2013 09:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754549Ab3JNJKk (ORCPT ); Mon, 14 Oct 2013 05:10:40 -0400 Received: from mga02.intel.com ([134.134.136.20]:17108 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754485Ab3JNJKk (ORCPT ); Mon, 14 Oct 2013 05:10:40 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 14 Oct 2013 02:10:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,491,1378882800"; d="scan'208";a="392597859" Received: from unknown (HELO rzhang1-mobl4.ccr.corp.intel.com) ([10.255.21.13]) by orsmga001.jf.intel.com with ESMTP; 14 Oct 2013 02:10:36 -0700 From: Zhang Rui To: rjw@sisk.pl Cc: linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko.nikula@linux.intel.com, mika.westerberg@linux.intel.com, Zhang Rui Subject: [PATCH 1/3] ACPI: add module autoloading support for ACPI enumerated devices Date: Mon, 14 Oct 2013 17:10:32 +0800 Message-Id: <1381741834-7334-1-git-send-email-rui.zhang@intel.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 An ACPI enumerated device may have its compatible id strings. To support the compatible ACPI ids (acpi_device->pnp.ids), we introduced acpi_driver_match_device() to match the driver->acpi_match_table and acpi_device->pnp.ids. For those drivers, MODULE_DEVICE_TABLE(acpi, xxx) is used to exports the driver module alias in the format of "acpi:device_compatible_ids". But in the mean time, the current code does not export the ACPI compatible strings as part of the module_alias for the ACPI enumerated devices, which will break the module autoloading. Take the following piece of code for example, static const struct acpi_device_id xxx_acpi_match[] = { { "INTABCD", 0 }, { } }; MODULE_DEVICE_TABLE(acpi, xxx_acpi_match); If this piece of code is used in a platform driver for an ACPI enumerated platform device, the platform driver module_alias is "acpi:INTABCD", but the uevent attribute of its platform device node is "platform:INTABCD:00" (PREFIX:pdev->name). If this piece of code is used in an i2c driver for an ACPI enumerated i2c device, the i2c driver module_alias is "acpi:INTABCD", but the uevent of its i2c device node is "i2c:INTABCD:00" (PREFIX:client->name). The reason why the module autoloading is not broken for now is that the uevent file of the ACPI device node is "acpi:INTABCD". Thus it is the ACPI device node creation that loads the platform/i2c driver. So this is a problem that will affect us the day when the ACPI bus is removed from device model. This patch introduces a new function to exporting ACPI ids as the module_alias, for the ACPI enumerate devices. For any drivers using MODULE_DEVICE_TALBE(acpi, blabla), the uevent file of its associated device must be fixed by invoking this function. Signed-off-by: Zhang Rui Reviewed-by: Mika Westerberg --- drivers/acpi/scan.c | 24 ++++++++++++++++++++++++ include/linux/acpi.h | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 407ad13..db6f879 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -111,6 +111,30 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias, return len; } +int acpi_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) +{ + struct acpi_device *acpi_dev; + int result; + int len; + + result = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev); + if (result) + return result; + + if (list_empty(&acpi_dev->pnp.ids)) + return 0; + + if (add_uevent_var(env, "MODALIAS=")) + return -ENOMEM; + len = create_modalias(acpi_dev, &env->buf[env->buflen - 1], + sizeof(env->buf) - env->buflen); + if (len >= (sizeof(env->buf) - env->buflen)) + return -ENOMEM; + env->buflen += len; + return 0; +} +EXPORT_SYMBOL(acpi_device_uevent_modalias); + static ssize_t acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { struct acpi_device *acpi_dev = to_acpi_device(dev); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index a5db4ae..117fa26 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -401,6 +401,8 @@ static inline bool acpi_driver_match_device(struct device *dev, return !!acpi_match_device(drv->acpi_match_table, dev); } +int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *); + #define ACPI_PTR(_ptr) (_ptr) #else /* !CONFIG_ACPI */ @@ -471,6 +473,12 @@ static inline bool acpi_driver_match_device(struct device *dev, return false; } +static inline int acpi_device_uevent_modalias(struct device *dev, + struct kobj_uevent_env *env) +{ + return -ENODEV; +} + #define ACPI_PTR(_ptr) (NULL) #endif /* !CONFIG_ACPI */