From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7E3CC43381 for ; Fri, 5 Mar 2021 16:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B709065004 for ; Fri, 5 Mar 2021 16:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231150AbhCEQO7 (ORCPT ); Fri, 5 Mar 2021 11:14:59 -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-Google-Smtp-Source: ABdhPJx+qwkCCU1ZThE1lqkMQEpKaShKnxdYkrIqoIcjTX9NcDSTzTVYQJxqtGGbJ78ONvj8GRUExQ== 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