From patchwork Wed Jun 25 17:30:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 32502 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 52BD0201EF for ; Wed, 25 Jun 2014 17:31:21 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wm4sf12113480obc.7 for ; Wed, 25 Jun 2014 10:31:20 -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=PyfLqajF5FcQIayZW7tDNhqZhkFQfknnoUd3C7giYsw=; b=PkUSJ/iMiDXkSyruePHlQvV+HpTq1/62lP0dAQKloX98hWJbRDQaIxznNFAR4u56pB LEMz06PI3hMq7fnJyvG7pvHlMnHM+Xh8OUsznXc2obe3d04JUdEE1PmiY3X+tCxk9VHd 0f8Jxrt3ODy4rJoxbYZpcXN69Hk//6t0jUprDjCWQWAyFKipMYpoaF2M+TQ6y25vrR+f 0P82BUhcUz2EF142MxmEjaG8dMc/xtxl9t8Cm6sV9s1KtSEgWl9AJJAQxb8Q+1903RN9 r6m8vErTRbcV386ISKn0fyxNBFmP2Iua50rCULIk1FAPwjefg2I6pqGZ0zTXbuPFDaGC k9vw== X-Gm-Message-State: ALoCoQlglGIfC71O9qd1iMC3sLoLG1nVZK/ccWUdfVUtGu9wPpKlAZ6a5ZpoqFq0E/wmQgiKQS66 X-Received: by 10.182.20.17 with SMTP id j17mr5307019obe.24.1403717480696; Wed, 25 Jun 2014 10:31:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.36 with SMTP id o33ls2750810qgo.76.gmail; Wed, 25 Jun 2014 10:31:20 -0700 (PDT) X-Received: by 10.52.12.129 with SMTP id y1mr1899164vdb.59.1403717480548; Wed, 25 Jun 2014 10:31:20 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id y3si2735833vdx.29.2014.06.25.10.31.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 10:31:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hy10so2272337vcb.1 for ; Wed, 25 Jun 2014 10:31:20 -0700 (PDT) X-Received: by 10.221.7.71 with SMTP id on7mr8343503vcb.18.1403717480438; Wed, 25 Jun 2014 10:31:20 -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 tc5csp306753vcb; Wed, 25 Jun 2014 10:31:19 -0700 (PDT) X-Received: by 10.68.139.225 with SMTP id rb1mr13587423pbb.153.1403717479609; Wed, 25 Jun 2014 10:31:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qf8si6217257pac.12.2014.06.25.10.31.18; Wed, 25 Jun 2014 10:31:18 -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 S1757934AbaFYRbE (ORCPT + 27 others); Wed, 25 Jun 2014 13:31:04 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:54832 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757830AbaFYRai (ORCPT ); Wed, 25 Jun 2014 13:30:38 -0400 Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.207.24]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s5PHUVSe001607; Wed, 25 Jun 2014 18:30:31 +0100 From: Sudeep Holla To: linux-kernel@vger.kernel.org Cc: sudeep.holla@arm.com, Heiko Carstens , Lorenzo Pieralisi , Greg Kroah-Hartman Subject: [PATCH 1/9] drivers: base: add new class "cpu" to group cpu devices Date: Wed, 25 Jun 2014 18:30:36 +0100 Message-Id: <1403717444-23559-2-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1403717444-23559-1-git-send-email-sudeep.holla@arm.com> References: <1403717444-23559-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.170 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 20da3ad..fe622e2 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 006b1bc..056b885 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 95978ad..8c0fc9b 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);