From patchwork Fri Jul 25 16:44:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 34297 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B642E20551 for ; Fri, 25 Jul 2014 16:44:46 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id j7sf12370504qaq.5 for ; Fri, 25 Jul 2014 09:44:46 -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=p+Uf91nA++vdDj7Fud4l4c0a0PgwpE5jN3J+TuEWHPA=; b=P4eiNE74le6uaStmbL1gluIMung6Y8qJT+vlEDr6mQ1cKFO4SiY2HhOh4zKjTUNWb1 V6La1h6oL6IZT6WDT39COm51Cnl2aN5f23r5LtH8KUpvf0nlzSnMzS0YkChTBGqug0XT YSKxFodeVU4Uezvw2/2wyC5WZOE/+99UZBxmONfZF4MAC1q09f1UTYnRR6aq0TYrOkvG UZFJkxc6VFX3icfBQcRBJUAkVHRVhSs46Ok/Q4xoO1kKzbkcNBuQvoddZBLj2xcmIIeZ 5W4fOEuQxZKPPrq6+86yB1Bnz6hS+JF8CuWuZtZ6CXbtHwgtqUTi+LSDZzAU2Kr6hn/N zQag== X-Gm-Message-State: ALoCoQkNp46hwN5BdFpGUM/I3l3cARV5MrsnqsjHdR2jB6fHYcA4rGHm/zd0cjoYAfSvh1v3fKXK X-Received: by 10.236.19.7 with SMTP id m7mr6202706yhm.35.1406306686522; Fri, 25 Jul 2014 09:44:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.169 with SMTP id x38ls1298556qgx.28.gmail; Fri, 25 Jul 2014 09:44:46 -0700 (PDT) X-Received: by 10.52.28.231 with SMTP id e7mr3343089vdh.55.1406306686415; Fri, 25 Jul 2014 09:44:46 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id sd9si7896276vdc.26.2014.07.25.09.44.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Jul 2014 09:44:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so7786179vcb.3 for ; Fri, 25 Jul 2014 09:44:46 -0700 (PDT) X-Received: by 10.221.47.9 with SMTP id uq9mr3966169vcb.48.1406306686209; Fri, 25 Jul 2014 09:44:46 -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.37.5 with SMTP id tc5csp51540vcb; Fri, 25 Jul 2014 09:44:45 -0700 (PDT) X-Received: by 10.70.54.102 with SMTP id i6mr20053815pdp.25.1406306684978; Fri, 25 Jul 2014 09:44:44 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rl10si9709810pbc.161.2014.07.25.09.44.43 for ; Fri, 25 Jul 2014 09:44:44 -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 S1760904AbaGYQom (ORCPT + 12 others); Fri, 25 Jul 2014 12:44:42 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:53866 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1760682AbaGYQol (ORCPT ); Fri, 25 Jul 2014 12:44:41 -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 s6PGiX0D031501; Fri, 25 Jul 2014 17:44:34 +0100 From: Sudeep Holla To: LKML Cc: sudeep.holla@arm.com, Heiko Carstens , Lorenzo Pieralisi , Greg Kroah-Hartman Subject: [PATCH v2 1/9] drivers: base: add new class "cpu" to group cpu devices Date: Fri, 25 Jul 2014 17:44:44 +0100 Message-Id: <1406306692-7135-2-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1406306692-7135-1-git-send-email-sudeep.holla@arm.com> References: <1403717444-23559-1-git-send-email-sudeep.holla@arm.com> <1406306692-7135-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.172 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 006b1bc5297d..056b8854e4fb 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -322,6 +322,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 @@ -338,6 +339,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); @@ -423,5 +426,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);