From patchwork Thu Aug 21 10:59:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 35748 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f71.google.com (mail-qg0-f71.google.com [209.85.192.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1826520540 for ; Thu, 21 Aug 2014 11:03:19 +0000 (UTC) Received: by mail-qg0-f71.google.com with SMTP id f51sf27598653qge.6 for ; Thu, 21 Aug 2014 04:03:18 -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=nxHXuyn4C22JyKcti7OBNtBLU8v/9UX2aWlxfwjJEok=; b=M3B9POmBVdLhyUPrG0b6vC6Ss9kx8xhD4qxATlAbP0Fp6HHZPPEn+YRz107Viqosm1 hqcGrfbW0pv8oNd5HYe7+JwsvA3YoXMDMgqAh32PjUUJnoZSVw1lzZ+U85osJaFP/+0C nYnOH5PkUiHDyrxh6F4SLVa6DpKVvcAkbzcOi6jZQPNTBONkp01btXwtVyRRPZ2vfzo2 d+4A9ZYyvWgU8j1/8J78E0354cdsPz8TNo0LBIPpodiq02OApgJUZyXM6hDhLlW1lKM+ EpC/ZpDpLPxENahObix3KVhN63Rr3D0kKeeKB53Lee1+kOpn5hzbqyecUjMWzj3BYYH6 95Aw== X-Gm-Message-State: ALoCoQkWhmYjLg5bzGcf6QbgpE/FtlMrJ5ZNgTp+9KjzRcMM8SpJV6qswks651Gbl/5v4mvexUih X-Received: by 10.52.174.178 with SMTP id bt18mr2344754vdc.1.1408618998719; Thu, 21 Aug 2014 04:03:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.42 with SMTP id j39ls678979qge.89.gmail; Thu, 21 Aug 2014 04:03:18 -0700 (PDT) X-Received: by 10.220.97.138 with SMTP id l10mr23151453vcn.25.1408618998520; Thu, 21 Aug 2014 04:03:18 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id kc6si12191894vdb.69.2014.08.21.04.03.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Aug 2014 04:03:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ik5so10427468vcb.20 for ; Thu, 21 Aug 2014 04:03:18 -0700 (PDT) X-Received: by 10.221.44.69 with SMTP id uf5mr41187995vcb.4.1408618998437; Thu, 21 Aug 2014 04:03:18 -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 uj3csp125724vcb; Thu, 21 Aug 2014 04:03:17 -0700 (PDT) X-Received: by 10.70.88.140 with SMTP id bg12mr59624339pdb.106.1408618997413; Thu, 21 Aug 2014 04:03:17 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sk6si36010037pab.97.2014.08.21.04.03.16 for ; Thu, 21 Aug 2014 04:03:17 -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 S1754749AbaHULDJ (ORCPT + 26 others); Thu, 21 Aug 2014 07:03:09 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:53552 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754019AbaHULAS (ORCPT ); Thu, 21 Aug 2014 07:00:18 -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 s7LB08RO024643; Thu, 21 Aug 2014 12:00:10 +0100 From: Sudeep Holla To: LKML Cc: sudeep.holla@arm.com, Heiko Carstens , Lorenzo Pieralisi , Stephen Boyd , Greg Kroah-Hartman Subject: [PATCH v3 03/11] drivers: base: add new class "cpu" to group cpu devices Date: Thu, 21 Aug 2014 11:59:46 +0100 Message-Id: <1408618794-28497-4-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1408618794-28497-1-git-send-email-sudeep.holla@arm.com> References: <1406306692-7135-1-git-send-email-sudeep.holla@arm.com> <1408618794-28497-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.175 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 creates a new class called "cpu" and assigns it to all the cpu devices. This helps in grouping all the cpu devices and associated child devices under the same class. This patch also: 1. modifies the get_parent_device to return the legacy path (/sys/devices/system/cpu/..) for the cpu class devices to support existing sysfs ABI 2. avoids creating link in the class directory pointing to the device as there would be per-cpu instance of these devices with the same name 3. makes sure subsystem symlink continues pointing to cpu bus instead of cpu class for cpu devices Signed-off-by: Sudeep Holla Cc: Greg Kroah-Hartman --- drivers/base/core.c | 39 +++++++++++++++++++++++++++++++++------ drivers/base/cpu.c | 7 +++++++ include/linux/cpu.h | 2 ++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 20da3ad1696b..fe622e2a48d0 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -10,6 +10,7 @@ * */ +#include #include #include #include @@ -742,6 +743,12 @@ static struct kobject *get_device_parent(struct device *dev, return &block_class.p->subsys.kobj; } #endif + /* + * if the device is in cpu class, then use the default/legacy + * /sys/devices/system/cpu/.. path + */ + if (dev->class == cpu_class) + return &parent->kobj; /* * If we have no parent, we live in "virtual". @@ -808,11 +815,17 @@ static int device_add_class_symlinks(struct device *dev) if (!dev->class) return 0; - error = sysfs_create_link(&dev->kobj, - &dev->class->p->subsys.kobj, - "subsystem"); - if (error) - goto out; + /* + * the subsystem symlink in each cpu device needs to continue + * pointing to cpu bus + */ + if (dev->bus != &cpu_subsys) { + error = sysfs_create_link(&dev->kobj, + &dev->class->p->subsys.kobj, + "subsystem"); + if (error) + goto out; + } if (dev->parent && device_is_not_partition(dev)) { error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, @@ -826,6 +839,13 @@ static int device_add_class_symlinks(struct device *dev) if (sysfs_deprecated && dev->class == &block_class) return 0; #endif + /* + * don't create a link in the cpu class directory pointing to the + * device as there would be per-cpu instance of these devices with + * the same name + */ + if (dev->class == cpu_class) + return 0; /* link in the class directory pointing to the device */ error = sysfs_create_link(&dev->class->p->subsys.kobj, @@ -851,11 +871,18 @@ static void device_remove_class_symlinks(struct device *dev) if (dev->parent && device_is_not_partition(dev)) sysfs_remove_link(&dev->kobj, "device"); - sysfs_remove_link(&dev->kobj, "subsystem"); + + /* if subsystem points to cpu bus, bus_remove_device will remove it */ + if (dev->bus != &cpu_subsys) + sysfs_remove_link(&dev->kobj, "subsystem"); #ifdef CONFIG_BLOCK if (sysfs_deprecated && dev->class == &block_class) return; #endif + /* symlinks are not created for cpu class devices, nothing to remove */ + if (dev->class == cpu_class) + return; + sysfs_delete_link(&dev->class->p->subsys.kobj, &dev->kobj, dev_name(dev)); } diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 277a9cfa9040..8e380214625d 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -319,6 +319,7 @@ static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env) } #endif +struct class *cpu_class; /* * register_cpu - Setup a sysfs device for a CPU. * @cpu - cpu->hotpluggable field set to 1 will generate a control file in @@ -335,6 +336,8 @@ int register_cpu(struct cpu *cpu, int num) memset(&cpu->dev, 0x00, sizeof(struct device)); cpu->dev.id = num; cpu->dev.bus = &cpu_subsys; + cpu->dev.parent = cpu_subsys.dev_root; + cpu->dev.class = cpu_class; cpu->dev.release = cpu_device_release; cpu->dev.offline_disabled = !cpu->hotpluggable; cpu->dev.offline = !cpu_online(num); @@ -420,5 +423,9 @@ void __init cpu_dev_init(void) if (subsys_system_register(&cpu_subsys, cpu_root_attr_groups)) panic("Failed to register CPU subsystem"); + cpu_class = class_create(THIS_MODULE, "cpu"); + if (IS_ERR(cpu_class)) + panic("Failed to register CPU class"); + cpu_dev_register_generic(); } diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 95978ad7fcdd..8c0fc9b0acad 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -39,6 +39,8 @@ 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 class *cpu_class; + #ifdef CONFIG_HOTPLUG_CPU extern void unregister_cpu(struct cpu *cpu); extern ssize_t arch_cpu_probe(const char *, size_t);