From patchwork Wed Sep 3 17:00:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 36614 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B4072039B for ; Wed, 3 Sep 2014 17:01:18 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id eu11sf85406111pac.7 for ; Wed, 03 Sep 2014 10:01:12 -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=GkTZ8XRYkEg+D8OVYrTjAG8APaUBaWpUC4EIFnrufO0=; b=RtS01SxBlclLtvCHSqz1gB++UP7+lhFqSUHnpOHsgoT7/UGU48MEXPeuwKd4dEORQe odqekK45TEkJOs64TzQfABijphHJ6n3mgFZARLtHfg7ThDbKd8ZR+VcwynX/+QcF4CUk oXf9Svdj/BsT6iPvz+7xzjdiZ1dqWar7viRYO0oqr+iyeMhHeX99IeuM+Uio6TM9yFz9 3lT8HFZFXkmRomjAlbwDXlwBDy8Wiqo4s8h9l44qfgYhaWO9OB0R3S1eSCT7LkB1YSFe NMO22Am/Mu7wa85bXIfC8jqP2HntI9Sbu8FIHF/dOJUHOljtP+IEDw6fHuGfUnlardOt Qycw== X-Gm-Message-State: ALoCoQlECcwLXIThqbZ2IFlYbruyEkrUfTO9o7TMoneaTUColOYYT/Zd8euHbE2tqqACB12G+tQB X-Received: by 10.66.163.41 with SMTP id yf9mr23502004pab.36.1409763672124; Wed, 03 Sep 2014 10:01:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.105 with SMTP id o96ls2831675qgo.35.gmail; Wed, 03 Sep 2014 10:01:11 -0700 (PDT) X-Received: by 10.221.61.5 with SMTP id wu5mr35892553vcb.13.1409763671896; Wed, 03 Sep 2014 10:01:11 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id cf5si3990660vcb.46.2014.09.03.10.01.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 10:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ik5so8999250vcb.7 for ; Wed, 03 Sep 2014 10:01:11 -0700 (PDT) X-Received: by 10.221.5.137 with SMTP id og9mr36446198vcb.18.1409763671787; Wed, 03 Sep 2014 10:01:11 -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 uj3csp710671vcb; Wed, 3 Sep 2014 10:01:11 -0700 (PDT) X-Received: by 10.70.49.34 with SMTP id r2mr3673488pdn.134.1409763669984; Wed, 03 Sep 2014 10:01:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ic5si12219877pbc.128.2014.09.03.10.00.57 for ; Wed, 03 Sep 2014 10:01:01 -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 S932890AbaICRAi (ORCPT + 26 others); Wed, 3 Sep 2014 13:00:38 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:53419 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752645AbaICRAh (ORCPT ); Wed, 3 Sep 2014 13:00:37 -0400 Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.207.142]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s83H0SkC032633; Wed, 3 Sep 2014 18:00:29 +0100 From: Sudeep Holla To: LKML Cc: Sudeep Holla , Heiko Carstens , Lorenzo Pieralisi , Greg Kroah-Hartman , David Herrmann , Kay Sievers Subject: [PATCH v4 03/11] drivers: base: add cpu_device_create to support per-cpu devices Date: Wed, 3 Sep 2014 18:00:09 +0100 Message-Id: <1409763617-17074-4-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409763617-17074-1-git-send-email-sudeep.holla@arm.com> References: <1409763617-17074-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.220.176 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 Cc: David Herrmann Cc: Kay Sievers Tested-by: Stephen Boyd --- 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 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);