Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1700576pxb; Mon, 13 Sep 2021 03:38:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOzEnk/TC7TrbnkSNbP8aWat7FJEFk+b3/QV2YUbAuM6ECGE22B4rPYxjXL+OK2iFDwxdP X-Received: by 2002:a5d:9707:: with SMTP id h7mr8309664iol.28.1631529529392; Mon, 13 Sep 2021 03:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631529529; cv=none; d=google.com; s=arc-20160816; b=JtI11jf3e+iOJXoarudUy5R80/44OeHA3wJ45jrX9xK4eSxU5pjrwSXwh4Gcdpk2hM ymff24pDvVcITRIPbyh9M+ObQoJ3YsXqsKcHs/sdCgJkc6PC6406Xu6AWh+3aGftL58H UQ49AH6PK0MFFNEedGjvDzcqFxNqk9d/PIOCUvCIbAxni+EUoHfDu21xOdBELP/40hbI 4ZoALcplW4wslaot5PimKkqpKjGgTXtnEH23F3OzEC7BaMWKoobzXyzvv2AyTi/dkq+J A1zYVRv/uSDUg3xff4l1qakw9kji7s+KPfAhst2yErwrdTvfX7gpFYoT1Rl6opyuT23S BHVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=4ojy6cEsFHk10XZ8gTjQ+8LmjK4t0ENByVBTa8Pq7oU=; b=OqkIDvPiC2TunNmGxB/4zPLiVNkGbhvRzY2Op4gcddtA2Gq7p5SAzQSiMMzCpq0fhf KsM5Z7BHiAfhVOdAgoFmmBeRfnnzQQqsKmuUVC0WphxnPyBL21HFXM8o86nYAs3v/TJ9 QI8zruO94eYbjOSrxNwB1snJ8OHacziW9hrZVlE1j25IVSE64wBcw8ibLDzpM4sNjGMt 9jiQvMcQJo+UtT2W0HYMjwsVtYheJ1FzJ1k/BFJI6LpcIOVi01nlNauI03ngAv7LV+KR hoJcYKONZRgzEwvgDaN4Q/t4debEr4rGJsh0GevB9S5P9UDYfUdCtpHCWQBjwYOdu5FG Qd+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=QuwYcmTh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l18si5795714ilc.72.2021.09.13.03.38.38; Mon, 13 Sep 2021 03:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=QuwYcmTh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237875AbhIMK2m (ORCPT + 99 others); Mon, 13 Sep 2021 06:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238002AbhIMK2l (ORCPT ); Mon, 13 Sep 2021 06:28:41 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA9CFC061574 for ; Mon, 13 Sep 2021 03:27:25 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id gp20-20020a17090adf1400b00196b761920aso6105089pjb.3 for ; Mon, 13 Sep 2021 03:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=4ojy6cEsFHk10XZ8gTjQ+8LmjK4t0ENByVBTa8Pq7oU=; b=QuwYcmThUMsaKLPdimS74jJZtMpt3AGfCzcrliBD84wbo8kIKgW2stgTtjKVEPOXzT vK9j9FtLGWqdxd6JBDkTbSw7MzcmTUtHHx+dCGDznrQl20OvaAzYP3TYfHi2eMMB5YFp YCkUY17hm27ZRdbvTJgKTQ0nJX132ZwjKAu2TcGOyHglENSby2fAe19CY5+OJ1lJs/Nu Bwr91VjUS+jm5EFG/8ZyIXrPRxbKQ4aYh4rt4sCDZgA6IFSQJcjUmb8xcmj10W+S4/kd 3thgZ1vmfDQJNAI6o6aVXaEtJ18Ie5qHSQK4ytd6+usHvlg09Em1q5wuNTzsT1gu7klb clHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=4ojy6cEsFHk10XZ8gTjQ+8LmjK4t0ENByVBTa8Pq7oU=; b=a6q3QrNEEjxQDoSx9Mdrv8ucidw8XlGn21KOTzOLCmn9+Ka98/86ovUuySTH5ypCp3 I6H3Tf6Ta2lCJ6OKIWyzYGDrgZ6KkpJLRimGIhHUoaaTefqOtxiGy+Q+kJWigLaCF3DA Gua8zpzd62TmPwRUz7kIR96v7WOfbszLVT77mm0HpSXO6dlaimFbzv0ogkcK4VWJDpz/ XkLr+PZK7xHrqLn77+yjRy2sAb5Yrff9nxjRQyzjyPsCPwhXeHld5fzTfn2IXx77x3Ew H+qiOItk4t2m1v3TBrjhPSnouRszvixcS6pZJqnC02z3ZvrIk6C17/+F0Aih3eXQjAmY m1ew== X-Gm-Message-State: AOAM531e8U2jgoy302uXV5BkmwV9FfZIKz/i1KeZIFucM9NosNyu8efw gThtkDIj2ahOmziOEm6PyEkTLQyIYIxrqQ== X-Received: by 2002:a17:902:b218:b029:11a:bf7b:1a80 with SMTP id t24-20020a170902b218b029011abf7b1a80mr9787613plr.82.1631528845385; Mon, 13 Sep 2021 03:27:25 -0700 (PDT) Received: from [192.168.10.23] (124-171-108-209.dyn.iinet.net.au. [124.171.108.209]) by smtp.gmail.com with ESMTPSA id q12sm6663523pfj.153.2021.09.13.03.27.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Sep 2021 03:27:24 -0700 (PDT) Message-ID: Date: Mon, 13 Sep 2021 20:27:18 +1000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Thunderbird/92.0 Subject: Re: [PATCH V3 5/5] virtio: Bind virtio device to device-tree node Content-Language: en-US To: "Michael S. Tsirkin" Cc: Viresh Kumar , Jason Wang , Rob Herring , Arnd Bergmann , Jean-Philippe Brucker , "Enrico Weigelt, metux IT consult" , Vincent Guittot , Arnd Bergmann , devicetree@vger.kernel.org, Bill Mills , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, =?UTF-8?Q?C=c3=a9dric_Le_Goater?= References: <454a58f998b0d16847d72a97b32192829fab2c8c.1627273794.git.viresh.kumar@linaro.org> <20210913053816-mutt-send-email-mst@kernel.org> From: Alexey Kardashevskiy In-Reply-To: <20210913053816-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/09/2021 19:45, Michael S. Tsirkin wrote: > On Mon, Sep 13, 2021 at 07:19:17PM +1000, Alexey Kardashevskiy wrote: >> >> >> On 26/07/2021 14:51, Viresh Kumar wrote: >>> Bind the virtio devices with their of_node. This will help users of the >>> virtio devices to mention their dependencies on the device in the DT >>> itself. Like GPIO pin users can use the phandle of the device node, or >>> the node may contain more subnodes to add i2c or spi eeproms and other >>> users. >>> >>> Reviewed-by: Arnd Bergmann >>> Signed-off-by: Viresh Kumar >>> --- >>> drivers/virtio/virtio.c | 57 ++++++++++++++++++++++++++++++++++++++--- >>> 1 file changed, 54 insertions(+), 3 deletions(-) >>> >>> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c >>> index 4b15c00c0a0a..d001e84a5b23 100644 >>> --- a/drivers/virtio/virtio.c >>> +++ b/drivers/virtio/virtio.c >>> @@ -4,6 +4,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> >>> /* Unique numbering for virtio devices. */ >>> @@ -292,6 +293,9 @@ static int virtio_dev_remove(struct device *_d) >>> >>> /* Acknowledge the device's existence again. */ >>> virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE); >>> + >>> + of_node_put(dev->dev.of_node); >>> + >>> return 0; >>> } >>> >>> @@ -319,6 +323,43 @@ void unregister_virtio_driver(struct virtio_driver *driver) >>> } >>> EXPORT_SYMBOL_GPL(unregister_virtio_driver); >>> >>> +static int virtio_device_of_init(struct virtio_device *dev) >>> +{ >>> + struct device_node *np, *pnode = dev_of_node(dev->dev.parent); >>> + char compat[] = "virtio,XXXXXXXX"; /* Reserve enough space 32-bit id */ >>> + int ret, count; >>> + >>> + if (!pnode) >>> + return 0; >>> + >>> + count = of_get_available_child_count(pnode); >>> + if (!count) >>> + return 0; >>> + >>> + /* There can be only 1 child node */ >>> + if (WARN_ON(count > 1)) >>> + return -EINVAL; >>> + >>> + np = of_get_next_available_child(pnode, NULL); >>> + if (WARN_ON(!np)) >>> + return -ENODEV; >>> + >>> + BUG_ON(snprintf(compat, sizeof(compat), "virtio,%x", dev->id.device) >= >>> + sizeof(compat)); >>> + >>> + if (!of_device_is_compatible(np, compat)) { >> >> >> This broke powerpc/pseries as there these virtio devices are PCI so >> there is no "compat" - PCI vendor id/device ids play role of "compat". >> Thanks, > > Hmm now that you say this I wonder why do we bother > with this check, too. When can this be invoked for something > that is not a virtio device? And is it enough to just > skip of_node initialization then? I am not following here, the problem device is virtio-scsi which is virtio-derived, or you meant that virtio which hosts virtio-bus? > >> >> >> >>> + ret = -EINVAL; > > > So basically ret = 0 above? Yup, this does fix it. Thanks, > > >>> + goto out; >>> + } >>> + >>> + dev->dev.of_node = np; >>> + return 0; >>> + >>> +out: >>> + of_node_put(np); >>> + return ret; >>> +} >>> + >>> /** >>> * register_virtio_device - register virtio device >>> * @dev : virtio device to be registered >>> @@ -343,6 +384,10 @@ int register_virtio_device(struct virtio_device *dev) >>> dev->index = err; >>> dev_set_name(&dev->dev, "virtio%u", dev->index); >>> >>> + err = virtio_device_of_init(dev); >>> + if (err) >>> + goto out_ida_remove; >>> + >>> spin_lock_init(&dev->config_lock); >>> dev->config_enabled = false; >>> dev->config_change_pending = false; >>> @@ -362,10 +407,16 @@ int register_virtio_device(struct virtio_device *dev) >>> */ >>> err = device_add(&dev->dev); >>> if (err) >>> - ida_simple_remove(&virtio_index_ida, dev->index); >>> + goto out_of_node_put; >>> + >>> + return 0; >>> + >>> +out_of_node_put: >>> + of_node_put(dev->dev.of_node); >>> +out_ida_remove: >>> + ida_simple_remove(&virtio_index_ida, dev->index); >>> out: >>> - if (err) >>> - virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED); >>> + virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED); >>> return err; >>> } >>> EXPORT_SYMBOL_GPL(register_virtio_device); >>> >> >> -- >> Alexey > -- Alexey