From patchwork Tue Sep 30 13:48:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 38143 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1DE0020549 for ; Tue, 30 Sep 2014 13:48:45 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id d1sf1378644wiv.2 for ; Tue, 30 Sep 2014 06:48:44 -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=B1Qz9BVIz+zjf4VxORxXm1InxyynJYXNm6JS0+WI0sM=; b=MNlu5QLtaqWcObsp9c6tKdOCqb5cQBbFpWeID0rtE5s+yK3tkNNAoAnZzddGnebwc+ Au0RLVLxtQT2zXDlJdYkWDyEAA9zCJbcq3QdbgCFrbeq1olD72NjgJw9/HZdVzBR82ph eBOTV6ZbzBkO46Iyt7+OtpR82ZL9XsCm8CTN2bzx5JGlU/nqrLSrhOuxdTBxIqIwCxUm bTbxp5Y46yfiRx3KszHo/x+saqo7ieVo8vlO6XSfuF7bBgSBcSZ8KgI2/RM2zHjUjo9J PcAgrmOIofnCq6OQW7oHJroGl0mp28UjgCA81Yocf4ztGJLSNRaY43FKLX91a5E8iPD6 97XA== X-Gm-Message-State: ALoCoQnFciMvjwMxF/AFqzQq1XCGFfLmA/v93PxZ9KiC9drrJybegfBB/jTi/rnYYKYcWgOJzA2X X-Received: by 10.152.19.131 with SMTP id f3mr6971457lae.0.1412084923972; Tue, 30 Sep 2014 06:48:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.129 with SMTP id o1ls42093lal.75.gmail; Tue, 30 Sep 2014 06:48:43 -0700 (PDT) X-Received: by 10.112.182.42 with SMTP id eb10mr45316750lbc.7.1412084923798; Tue, 30 Sep 2014 06:48:43 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id h5si22795946laf.110.2014.09.30.06.48.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 06:48:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id n15so5495041lbi.26 for ; Tue, 30 Sep 2014 06:48:43 -0700 (PDT) X-Received: by 10.152.5.168 with SMTP id t8mr46948047lat.67.1412084923270; Tue, 30 Sep 2014 06:48:43 -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.112.130.169 with SMTP id of9csp349599lbb; Tue, 30 Sep 2014 06:48:42 -0700 (PDT) X-Received: by 10.66.177.135 with SMTP id cq7mr51128997pac.44.1412084921503; Tue, 30 Sep 2014 06:48:41 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si27051716pat.126.2014.09.30.06.48.35 for ; Tue, 30 Sep 2014 06:48:41 -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 S1752090AbaI3Nsd (ORCPT + 27 others); Tue, 30 Sep 2014 09:48:33 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:51009 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751119AbaI3Ns3 (ORCPT ); Tue, 30 Sep 2014 09:48:29 -0400 Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.207.153]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s8UDmMqH025876; Tue, 30 Sep 2014 14:48:22 +0100 From: Sudeep Holla To: LKML Cc: Sudeep Holla , Heiko Carstens , Lorenzo Pieralisi , Greg Kroah-Hartman , David Herrmann , Kay Sievers Subject: [PATCH v5 03/11] drivers: base: add cpu_device_create to support per-cpu devices Date: Tue, 30 Sep 2014 14:48:24 +0100 Message-Id: <1412084912-2767-4-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412084912-2767-1-git-send-email-sudeep.holla@arm.com> References: <1412084912-2767-1-git-send-email-sudeep.holla@arm.com> 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.217.181 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: , 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 Tested-by: Stephen Boyd Cc: Greg Kroah-Hartman Cc: David Herrmann Cc: Kay Sievers Acked-by: Greg Kroah-Hartman --- drivers/base/cpu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/cpu.h | 4 ++++ 2 files changed, 58 insertions(+) diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 4d8a56406fbb..f829a4c71749 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);