Received: by 10.223.176.46 with SMTP id f43csp1490040wra; Sat, 20 Jan 2018 20:59:57 -0800 (PST) X-Google-Smtp-Source: AH8x224zRPbFA8y5z30EBLSxL/n0y04PR8CMYM3ovPWrtf1rcBCqDlnlSAnzAZz8Ela1vZnrHQ55 X-Received: by 10.98.31.131 with SMTP id l3mr4360349pfj.116.1516510797021; Sat, 20 Jan 2018 20:59:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516510796; cv=none; d=google.com; s=arc-20160816; b=RyNFu4XVozc3XsP2mIkKhHCAmfV7os2TulsKYM5h7pi9wiL7HY7oIsjq9UET11S0JF F9TPhGKvmWtkWd5+c5rfk18NT+eUgVGPtrr+pra0MZw4Y0zXWHPSsrv+q//0+kZBxAON 6nNW3HGd1VePN4pKSPnaSi8EhWQmXIF1zxNSL3D92AK/LiUwXBFADrN7jkAYZntWVzsS 7P3AXKOzN48x//erX3t9MRTI0lAWZ6MdRoK9Q6RCg+yvBMsan8hMb7/bifRCxTYeqJ+q OV5Yaol9m+HRFeTiRRpiOPeRfuW21k2y6OV90Eo7p7+EfmE20jvsDmKxEOA42IHrB1hR 9cNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=P8arUG/Dt6du/v9sDRFCc67zI8koOsZtnYHuTmd9aIs=; b=EiNIgWTRATv6qhYnTv1/c65iL+eGELX4voie/8cUJ87mgfqt2iSpJjEdvESd64ntHI pIVaVCd/z9aBJw+JJvIjXMZC+kgLK7+U1k1cId+YbEj6vAt630MIsPC9HBg9WW7Xgym1 2PLFCHaIQhKTrAvwpXASPFhnzF1vc1TKhfTDLeX/Uovg5nAXybj86RFGrORcibeFiRXh yGVKvYWpLhSDY1cX/xtAB1qmIwujJjhNZUupXK97H2I9RDy2U0EhN7VRfbfauKrG3SJg PTbXG6c53pWAq9G23YMJMR818k7gyCTYtDIFg2sS6yZ1nhZUG/+AqowCDoqSCm61PTLt jkDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DHmFljWD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q24si11818067pgn.679.2018.01.20.20.59.41; Sat, 20 Jan 2018 20:59:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DHmFljWD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750923AbeAUE7Q (ORCPT + 99 others); Sat, 20 Jan 2018 23:59:16 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:46069 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750817AbeAUE7N (ORCPT ); Sat, 20 Jan 2018 23:59:13 -0500 Received: by mail-pg0-f65.google.com with SMTP id c194so4486015pga.12; Sat, 20 Jan 2018 20:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=P8arUG/Dt6du/v9sDRFCc67zI8koOsZtnYHuTmd9aIs=; b=DHmFljWDCa/ydf+cLNU6eOeweq5QMhYiFHUTs6cxUUmRdj8I7ak9gxKXoLqlg5NJv2 /f56Kf5iS0EuilmEPwb6QbWYCtCo0TZGXeUK5HZY1SBqpYbUy2tMt3QybAUxzIDh6GMe DC7AOVcjFmbCKiz0xSeS4piu2Z4pRt7alPSwKrGhwFbRg6fTBvdMPQTox89/3AqZXbR9 OqyOhXIX/7XhG8XdZsJ9kEq3cPIXAj14AOIZhFFIjc/einop6zScNFJSdcOykaNUPg5p KOdale0nkSSlXY+Yx7eFOQVR/ku5zCtGPUWzaZz3v5Owz8gMACyFcEptr0Mmbi4HILav TXeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=P8arUG/Dt6du/v9sDRFCc67zI8koOsZtnYHuTmd9aIs=; b=lCMcY7ZWaapphOdDPw8aJiVQFqDk1hvujfmgYX2aU0IdWHg0QimEs82ARA9zJGSqK3 HXatgbiebDMj7/XpZeSx4mGsn/FD8dQuQxOWILFF9sp6CNji3NejKMZDWEfY5sYmnJET TBsifuPHJVY92WVuZqHguRJwQBFvlVFsV4AxSywQImxD2odCc2+7MdEMTueOpoQ6tkaf Ib7Exe21qM13w6XeRJTg53NtaHD+OWwmNp0K6QYA/znDGRHTKd33k0UNMlkyU1Xchefm Es4Xmt27yl1j2Thqf2UcsWO4UDQ3fSaQOVSfgcMxkbDoSCic2ZZN5HHyFSbyfAHnXdRD pinQ== X-Gm-Message-State: AKwxytdzoMvD0kXwfogLPF0fTRdggn7RlYLddXWizulT/NyocA+43jmk B9BuAKIVdoXLC6VXZxIOf9rlhjla X-Received: by 10.101.82.205 with SMTP id z13mr3655042pgp.29.1516510752510; Sat, 20 Jan 2018 20:59:12 -0800 (PST) Received: from [192.168.1.108] (c-73-67-222-53.hsd1.or.comcast.net. [73.67.222.53]) by smtp.gmail.com with ESMTPSA id e3sm24323567pfb.143.2018.01.20.20.59.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jan 2018 20:59:12 -0800 (PST) Subject: Re: [RFC v8 4/7] platform: x86: Add generic Intel IPC driver To: Heikki Krogerus , sathyanarayanan.kuppuswamy@linux.intel.com Cc: a.zummo@towertech.it, x86@kernel.org, wim@iguana.be, mingo@redhat.com, alexandre.belloni@free-electrons.com, qipeng.zha@intel.com, hpa@zytor.com, dvhart@infradead.org, tglx@linutronix.de, lee.jones@linaro.org, andy@infradead.org, souvik.k.chakravarty@intel.com, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org References: <5c66498c110e52343d810db9c281fe72d0d299cc.1509268570.git.sathyanarayanan.kuppuswamy@linux.intel.com> <20171123132916.GE17418@kuha.fi.intel.com> From: sathya Message-ID: Date: Sat, 20 Jan 2018 20:59:10 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171123132916.GE17418@kuha.fi.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Heikki, On 11/23/2017 05:29 AM, Heikki Krogerus wrote: > Hi, > > On Sun, Oct 29, 2017 at 02:49:57AM -0700, sathyanarayanan.kuppuswamy@linux.intel.com wrote: >> +/** >> + * devm_intel_ipc_dev_create() - Create IPC device >> + * @dev : IPC parent device. >> + * @devname : Name of the IPC device. >> + * @cfg : IPC device configuration. >> + * @ops : IPC device ops. >> + * >> + * Resource managed API to create IPC device with >> + * given configuration. >> + * >> + * Return : IPC device pointer or ERR_PTR(error code). >> + */ >> +struct intel_ipc_dev *devm_intel_ipc_dev_create(struct device *dev, >> + const char *devname, >> + struct intel_ipc_dev_cfg *cfg, >> + struct intel_ipc_dev_ops *ops) >> +{ >> + struct intel_ipc_dev **ptr, *ipc_dev; >> + int ret; >> + >> + if (!dev && !devname && !cfg) >> + return ERR_PTR(-EINVAL); >> + >> + if (intel_ipc_dev_get(devname)) { >> + dev_err(dev, "IPC device %s already exist\n", devname); >> + return ERR_PTR(-EINVAL); >> + } >> + >> + ptr = devres_alloc(devm_intel_ipc_dev_release, sizeof(*ptr), >> + GFP_KERNEL); >> + if (!ptr) >> + return ERR_PTR(-ENOMEM); >> + >> + ipc_dev = kzalloc(sizeof(*ipc_dev), GFP_KERNEL); >> + if (!ipc_dev) { >> + ret = -ENOMEM; >> + goto err_dev_create; >> + } >> + >> + ipc_dev->dev.class = &intel_ipc_class; >> + ipc_dev->dev.parent = dev; >> + ipc_dev->dev.groups = ipc_dev_groups; >> + ipc_dev->cfg = cfg; >> + ipc_dev->ops = ops; >> + >> + mutex_init(&ipc_dev->lock); >> + init_completion(&ipc_dev->cmd_complete); >> + dev_set_drvdata(&ipc_dev->dev, ipc_dev); >> + dev_set_name(&ipc_dev->dev, devname); >> + device_initialize(&ipc_dev->dev); >> + >> + ret = device_add(&ipc_dev->dev); >> + if (ret < 0) { >> + dev_err(&ipc_dev->dev, "%s device create failed\n", >> + __func__); >> + ret = -ENODEV; >> + goto err_dev_add; >> + } >> + >> + if (ipc_dev->cfg->mode == IPC_DEV_MODE_IRQ) { >> + if (devm_request_irq(&ipc_dev->dev, >> + ipc_dev->cfg->irq, >> + ipc_dev_irq_handler, >> + ipc_dev->cfg->irqflags, >> + dev_name(&ipc_dev->dev), >> + ipc_dev)) { >> + dev_err(&ipc_dev->dev, >> + "Failed to request irq\n"); >> + goto err_irq_request; >> + } >> + } > That looks really wrong to me. This is the class driver, so why are > you handling the interrupts of the devices in it? You are clearly > making assumption that the interrupt will always be used only for > command completion, but that may not be the case. No assumptions. Yes. I only considered the current usage. But I agree with your comment. I will fix it in next version. > > Just define completion callbacks, and let the drivers handle the > actual interrupts. > >> + *ptr = ipc_dev; >> + >> + devres_add(dev, ptr); >> + return ipc_dev; >> + >> +err_irq_request: >> + device_del(&ipc_dev->dev); >> +err_dev_add: >> + kfree(ipc_dev); >> +err_dev_create: >> + devres_free(ptr); >> + return ERR_PTR(ret); >> +} >> +EXPORT_SYMBOL_GPL(devm_intel_ipc_dev_create); >> + >> +static int __init intel_ipc_init(void) >> +{ >> + ipc_channel_lock_init(); >> + return class_register(&intel_ipc_class); >> +} >> + >> +static void __exit intel_ipc_exit(void) >> +{ >> + class_unregister(&intel_ipc_class); >> +} >> +subsys_initcall(intel_ipc_init); >> +module_exit(intel_ipc_exit); >> + >> +MODULE_LICENSE("GPL v2"); >> +MODULE_AUTHOR("Kuppuswamy Sathyanarayanan"); >> +MODULE_DESCRIPTION("Intel IPC device class driver"); > To be honest, creating an extra logical device for the IPC hosts, and > the entire class, all feel unnecessarily complex to me. I want to avoid client drivers using different APIs to call everyone of these IPC drivers. One solution for this issue is to use name of the device to get the device pointer and then use that pointer in common API to make IPC calls. This solution is similar to whats used in extcon framework. To implement this model either we have to use class type to group all these devices or implement a custom list to keep the references for all these devices. I preferred to go with class based grouping, so that I can use class_find_device() API to get the device pointer. > > The goal of this patch should be possible to achieve in a much simpler > and flexible way. IMO this patch needs to be redesigned. I am open for suggestions. I will send a separate mail to you discuss about the further details. > > > Thanks, >