Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2148603pxb; Fri, 5 Mar 2021 08:18:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxi0Bswm7HZEyNbfoEZgZRDiSfXKwJy+fGr1jGo8GG2IK7Za+xsOXnQpReXQ83IhyBZ8VGK X-Received: by 2002:a17:906:3685:: with SMTP id a5mr3023016ejc.352.1614961117793; Fri, 05 Mar 2021 08:18:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614961117; cv=none; d=google.com; s=arc-20160816; b=r5M8q+8cEZ7Y6YpyPLYcccHeBGwgHGyrla3duBP2tzexqzSwAPMG6gxaML6oO19Tgf W7yQ80sltpRzqMQGye9MSTK80bVo8g2BQb0KUWtJ5xPDpWJgNnZMSsZV6z0ozxVjIFYX kPjiPcbBeaEmE4MA9QjP6miRJFUlILFoBgPP3sXprtsQtpUt0YTgWfULasrb88OCbR4R 6RzR+CPsG9oRvxG8yO7aRn+rfYXrYzMj3qd5+Yol8hxXpexlFvPUuWWVQRSbnMaqb44m GUDvEMI0eTgcy5vUugeMp4OARTyKWnCd+TrL9Lt7GbnlEsuanWiJtPaimndLNr//Whgi ZhtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=gGF2B9jC4mRRbN7Sez5okSBrNKXE5BxhZsBexlqjeas=; b=FGA7+S8RjXstauurOeABVKy0/wwt9HOS78JvTJcQcABeCTGaO2kldj4B5/y+0X0d/i w6OeZs1/p/7l8nbySMAmb1jvuB+aek3/rL+EX/EGdMbtdcxL1RbCwhSX5cbtC1LAIsH6 goSVtBOIpIKtuUfaKe6JyqW8rYP3ELJOt273gCa5K1IRpThsW4m93keFRQSHagl2rV5k n0HNTXjMPthajNqbXHOzh8G9LPWjZwt0DQe6zlSo0H/yL+Hw4uqyuTt45hs77ErGssUl UWlV0Tfk3xw/Xu4kJXNbxp4IoP9FSkOFJ/rORmDnupoztmXexVDObhZqnk/4+j567K7g JzxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Iw3bICcV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si1637183ejc.687.2021.03.05.08.18.14; Fri, 05 Mar 2021 08:18:37 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=Iw3bICcV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbhCEQO6 (ORCPT + 99 others); Fri, 5 Mar 2021 11:14:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40822 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbhCEQOe (ORCPT ); Fri, 5 Mar 2021 11:14:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614960874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gGF2B9jC4mRRbN7Sez5okSBrNKXE5BxhZsBexlqjeas=; b=Iw3bICcVjpaUthAoFJRhAEpUkBLhIAtj/3RnH0GFYc5BWfYvfwN5cXJ81sJ4R87IS0djtE eWC7EY28l+FxlGEOHyyzTRBLe7Xza898NdIhlM5R3YWBEnxnbVjQ2M678k3/tctg3Wb0rR TQzo6zNcdf6575dlNRy13T0PwuSPPBk= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-405-Jrsve-QmOmWYvSHhxN6yUQ-1; Fri, 05 Mar 2021 11:14:32 -0500 X-MC-Unique: Jrsve-QmOmWYvSHhxN6yUQ-1 Received: by mail-ej1-f71.google.com with SMTP id n25so1070751ejd.5 for ; Fri, 05 Mar 2021 08:14:32 -0800 (PST) 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-language :content-transfer-encoding; bh=gGF2B9jC4mRRbN7Sez5okSBrNKXE5BxhZsBexlqjeas=; b=E3FMrt0rffVxJYhS58VvdEjzK048jJUOvV2mR2cQvfA31CEJIFUn1pJXVNemEuUchY Uqw0q0XVo5qZTp2a8aAyhqls2wLn9E5O6OVLpAYB6ebsVYf/6rLBGaDLuzz0gMXTb63w WYkJD2NOxjhK4n8t1aggomZky+wVP1R9yoGxJ5BmoeJqNJa0u34Awk9EbiS4yFememNx /uEvvtu1rX3wjfo2KINnbsQw8gG0vkClbRqFsjnPJZ93bq1hyUtKS4D1KFt79i6Ucvjr uEQwuuTG+yvJl/p52j68qA1HCHHv4XupOGBles/sQjrNGjvH254lj4xLV8oR+zAHbzNL ta8Q== X-Gm-Message-State: AOAM530UnLqS2WX6XujtiFZRMd0tURPZsSNDWU7pArE7nbHyCZVXzpL3 XZJfEfB3ryR5VyFeQv4zNpmL1PMWT+NjlwTPQuwIr44rPgVmCm+3whPNb0xj/EnluVRc6J+zeEw QeSx4SmnLpVjhdoXfnRKIP/9I X-Received: by 2002:a17:906:2dda:: with SMTP id h26mr2845481eji.163.1614960871419; Fri, 05 Mar 2021 08:14:31 -0800 (PST) X-Received: by 2002:a17:906:2dda:: with SMTP id h26mr2845463eji.163.1614960871253; Fri, 05 Mar 2021 08:14:31 -0800 (PST) Received: from x1.localdomain (2001-1c00-0c1e-bf00-1054-9d19-e0f0-8214.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:1054:9d19:e0f0:8214]) by smtp.gmail.com with ESMTPSA id de17sm1715896ejc.16.2021.03.05.08.14.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Mar 2021 08:14:30 -0800 (PST) Subject: Re: [PATCH 1/4] platform/x86: simatic-ipc: add main driver for Siemens devices To: Andy Shevchenko Cc: Henning Schild , Linux Kernel Mailing List , Linux LED Subsystem , Platform Driver , linux-watchdog@vger.kernel.org, Srikanth Krishnakar , Jan Kiszka , Gerd Haeussler , Guenter Roeck , Wim Van Sebroeck , Mark Gross , Pavel Machek References: <20210302163309.25528-1-henning.schild@siemens.com> <20210302163309.25528-2-henning.schild@siemens.com> <2fad304a-9e1e-c83d-7a9e-02b35ed22418@redhat.com> From: Hans de Goede Message-ID: Date: Fri, 5 Mar 2021 17:14:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 3/5/21 4:42 PM, Andy Shevchenko wrote: > On Thu, Mar 4, 2021 at 3:47 PM Hans de Goede wrote: >> On 3/4/21 11:11 AM, Andy Shevchenko wrote: >>> On Thu, Mar 4, 2021 at 8:36 AM Henning Schild >>> wrote: > > ... > >>>> +u32 simatic_ipc_get_membase0(unsigned int p2sb) >>>> +{ >>>> + u32 bar0 = 0; >>> >>>> +#ifdef CONFIG_PCI >>> >>> It's ugly besides the fact that you have a dependency. >>> >>>> + struct pci_bus *bus; >>> >>> Missed blank line. >>> >>>> + /* >>>> + * The GPIO memory is bar0 of the hidden P2SB device. Unhide the device >>>> + * to have a quick look at it, before we hide it again. >>>> + * Also grab the pci rescan lock so that device does not get discovered >>>> + * and remapped while it is visible. >>>> + * This code is inspired by drivers/mfd/lpc_ich.c >>>> + */ >>>> + bus = pci_find_bus(0, 0); >>>> + pci_lock_rescan_remove(); >>>> + pci_bus_write_config_byte(bus, p2sb, 0xE1, 0x0); >>>> + pci_bus_read_config_dword(bus, p2sb, PCI_BASE_ADDRESS_0, &bar0); >>>> + >>>> + bar0 &= ~0xf; >>>> + pci_bus_write_config_byte(bus, p2sb, 0xE1, 0x1); >>>> + pci_unlock_rescan_remove(); >>>> +#endif /* CONFIG_PCI */ >>>> + return bar0; >>>> +} >>>> +EXPORT_SYMBOL(simatic_ipc_get_membase0); >>> >>> Oy vey! I know what this is and let's do it differently. I have some >>> (relatively old) patch series I can send you privately for testing. >> >> This bit stood out the most to me too, it would be good if we can this fixed >> in some cleaner work. So I'm curious how things will look with Andy's work >> integrated. >> >> Also I don't think this should be exported. Instead this (or its replacement) >> should be used to get the address for an IOMEM resource to add the platform >> devices when they are instantiated. Then the platform-dev drivers can just >> use the regular functions to get their resources instead of relying on this >> module. > > I have published a WIP branch [1]. I have no means to test (I don't > know what hardware at hand I can use right now), but I made it compile > after 4 years of gathering dust... So I took a quick look at the following 2 commits: "platform/x86: p2sb: New Primary to Sideband bridge support library" "mfd: lpc_ich: Switch to generic p2sb_bar()" And this looks good to me, although compared to the code from this patch-set you are missing the pci_lock_rescan_remove(); and pci_unlock_rescan_remove(); calls. > Feel free to give any kind of comments or share your ideas on how it > can be improved (the above idea on IOMEM resource is interesting, but > devices are PCI, not sure how this can be done). The code added by this patch introduces a register_platform_devices() function which creates a bunch of platform-devices; and then the device-drivers for those call simatic_ipc_get_membase0() to get their base-address. My suggestion was to instead put the simatic_ipc_get_membase0() call inside the code instantiating the platform devices and to add the base-address for that pdev as IOMEM resource to the instantiated platform-devices. I hope this helps to clarify what I was trying to say. Regards, Hans