From patchwork Fri Aug 22 11:29:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 35795 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 072512057E for ; Fri, 22 Aug 2014 11:29:34 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp18sf61518681obc.1 for ; Fri, 22 Aug 2014 04:29:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=82lPQBcgFy620HudbCmy/5WYDZDvvdfaE5pcyekSTMM=; b=A1KgocsW8+px+6plLM9QZGgoF94mY7AUzXRJ6s9lqS9x7kn9wSnfgnqgm/OEOKpx6b 702dVH4CEFaqGr5d4aCvv751qRNW6/OPWHo1/YgtW4urMldGx2uuwZus8BDUN+YOOm1Z 0NYtBZGUrD5NMIxCjqr7pi+oPlOJ0xyLe3ad+vbto2JkFdfYfdwCO8oG/1+zI4+fsiwR j+x1EVE9uTaeQ3wH7PXI9a1GwCNCgIRrGqzbuQ3X5wZl/Py1XlwRuWH9xvWMluojKnBh SfdSz5im9DbqWQ6+TP7v3qRvv4cFUv/hGadbBtxdBIrDa10Wdv1r5+grRsKcxEjYJoWy XRfA== X-Gm-Message-State: ALoCoQn1trhABpV/hQjhjPOzQtEb/SWV9cphdnbZn1Reie3OpzgxBCXYqLvWdROV6SxApqeUdFWW X-Received: by 10.42.96.193 with SMTP id k1mr6107365icn.13.1408706974213; Fri, 22 Aug 2014 04:29:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.228 with SMTP id d91ls1270339qge.41.gmail; Fri, 22 Aug 2014 04:29:34 -0700 (PDT) X-Received: by 10.220.251.200 with SMTP id mt8mr3654769vcb.24.1408706974075; Fri, 22 Aug 2014 04:29:34 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id qp20si13364037vdb.6.2014.08.22.04.29.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Aug 2014 04:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so12204924vcb.14 for ; Fri, 22 Aug 2014 04:29:34 -0700 (PDT) X-Received: by 10.220.184.70 with SMTP id cj6mr3594644vcb.5.1408706973967; Fri, 22 Aug 2014 04:29:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp9346vcb; Fri, 22 Aug 2014 04:29:33 -0700 (PDT) X-Received: by 10.66.158.130 with SMTP id wu2mr5606297pab.59.1408706972725; Fri, 22 Aug 2014 04:29:32 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bf4si40433593pdb.231.2014.08.22.04.29.32 for ; Fri, 22 Aug 2014 04:29:32 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756083AbaHVL33 (ORCPT + 21 others); Fri, 22 Aug 2014 07:29:29 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:53090 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753476AbaHVL31 (ORCPT ); Fri, 22 Aug 2014 07:29:27 -0400 Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.207.61]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s7MBTFk9012300; Fri, 22 Aug 2014 12:29:15 +0100 From: Sudeep Holla To: LKML , Greg Kroah-Hartman Cc: Sudeep Holla , Heiko Carstens , Lorenzo Pieralisi , Stephen Boyd , David Herrmann , Kay Sievers Subject: [PATCH] drivers: base: add cpu_device_create to support per-cpu devices Date: Fri, 22 Aug 2014 12:29:23 +0100 Message-Id: <1408706963-23195-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sudeep.holla@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Sudeep Holla This patch adds a new function to create per-cpu devices. This helps in: 1. reusing the device infrastructure to create any cpu related attributes and corresponding sysfs instead of creating and dealing with raw kobjects directly 2. retaining the legacy path(/sys/devices/system/cpu/..) to support existing sysfs ABI 3. avoiding to create links in the bus directory pointing to the device as there would be per-cpu instance of these devices with the same name since dev->bus is not populated to cpu_sysbus on purpose Signed-off-by: Sudeep Holla Cc: Greg Kroah-Hartman --- drivers/base/cpu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/cpu.h | 4 ++++ 2 files changed, 58 insertions(+) Hi Greg, Here is the alternate solution I could come up with instead of creating cpu class. cpu_device_create is very similar to device_create_groups_vargs w/o class support, but I could not reuse anything else to avoid creating similar function. Let me know your thoughts/suggestions on this. Regards, Sudeep diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 277a9cfa9040..53f0c4141d05 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -363,6 +363,60 @@ struct device *get_cpu_device(unsigned cpu) } EXPORT_SYMBOL_GPL(get_cpu_device); +static void device_create_release(struct device *dev) +{ + kfree(dev); +} + +static struct device * +__cpu_device_create(struct device *parent, void *drvdata, + const struct attribute_group **groups, + const char *fmt, va_list args) +{ + struct device *dev = NULL; + int retval = -ENODEV; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) { + retval = -ENOMEM; + goto error; + } + + device_initialize(dev); + dev->parent = parent; + dev->groups = groups; + dev->release = device_create_release; + dev_set_drvdata(dev, drvdata); + + retval = kobject_set_name_vargs(&dev->kobj, fmt, args); + if (retval) + goto error; + + retval = device_add(dev); + if (retval) + goto error; + + return dev; + +error: + put_device(dev); + return ERR_PTR(retval); +} + +struct device *cpu_device_create(struct device *parent, void *drvdata, + const struct attribute_group **groups, + const char *fmt, ...) +{ + va_list vargs; + struct device *dev; + + va_start(vargs, fmt); + dev = __cpu_device_create(parent, drvdata, groups, fmt, vargs); + va_end(vargs); + return dev; +} +EXPORT_SYMBOL_GPL(cpu_device_create); + #ifdef CONFIG_GENERIC_CPU_AUTOPROBE static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL); #endif diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 95978ad7fcdd..bb790a5621c0 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -19,6 +19,7 @@ struct device; struct device_node; +struct attribute_group; struct cpu { int node_id; /* The node which contains the CPU */ @@ -39,6 +40,9 @@ extern void cpu_remove_dev_attr(struct device_attribute *attr); extern int cpu_add_dev_attr_group(struct attribute_group *attrs); extern void cpu_remove_dev_attr_group(struct attribute_group *attrs); +extern struct device *cpu_device_create(struct device *parent, void *drvdata, + const struct attribute_group **groups, + const char *fmt, ...); #ifdef CONFIG_HOTPLUG_CPU extern void unregister_cpu(struct cpu *cpu); extern ssize_t arch_cpu_probe(const char *, size_t);