Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp524910ybv; Thu, 20 Feb 2020 02:53:03 -0800 (PST) X-Google-Smtp-Source: APXvYqzjbdX+O6TsufjRX+2Efb8BP0aF89VyWjsMebG4bGRHZ3Z9CZtkFIg+dQXp5prUZ7O/cYH6 X-Received: by 2002:a05:6808:611:: with SMTP id y17mr1437565oih.146.1582195983073; Thu, 20 Feb 2020 02:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582195983; cv=none; d=google.com; s=arc-20160816; b=AdgdMMT9Cuv1SKTqgt/IAngPd4hY2wFXpytAeNQomNcmnM4Suy3Yi4SYpgYFxl3+O9 bnq0F5b9ObUBU2w7vzGeWKHVUmEs4Q9ohlNAlKKnQ4D8fwl5XqG09ZgthiXv2a7esWNw Mw6nMVDBudcPG8qgUQov7iB0tsCoj4OAa7Oa2PpaYM9/gbOP+fVqPRH21AiknnpUXIFh jnSB0v/geMrSBD7mrNz3UI+ZC9bGMDX4UtLdUKdP9nzXBxlNPlcVlgICXlVKCtvsVwlt sWxara2gyqFdU+nhysQQmV4vPJnGfWkXqt9vBAKabdGcG08HE86u5admA/u/Hn6XE1Lw R8uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=+B/hnwXCfgAg+LBsQwB1KtJRN7kPjQzDj6XDAKg3dew=; b=xKIcUeeNQPwpBGmhgH3wc9SEIhCgDrPS4Pe2X7O7fVk6ksc2ZQ04SOf+5keKBrU86o Ftiui0Y2Iv8WWWqfoi4xZi0dSqE8E+WEqUEBiiOK/cgl8pEib0jSuXK6HJVpgS041ORP tK3YkgkWFQBHNckTasnxl79egFCZuB544RyOyHuGo/LaSSQyBor23ufEsb3Y4ottEGXf 1Qbmutifnaz+42PiL+WWDdX+B44lPoNBUzDgI6IbzJgVeYk8ZtTjgcSwRo9pCRwOw7zT ToHBfdhaj9v4YkBPqYgUIlSbdbVQCVjuwTyWPRTRfbZeOpW5DPv+lizIC/iWqLJfD5nw NG0w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a4si1409840otq.98.2020.02.20.02.52.50; Thu, 20 Feb 2020 02:53:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726885AbgBTKwm (ORCPT + 99 others); Thu, 20 Feb 2020 05:52:42 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:2447 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726700AbgBTKwm (ORCPT ); Thu, 20 Feb 2020 05:52:42 -0500 Received: from lhreml701-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id ED46A89E090926DFCD66; Thu, 20 Feb 2020 10:52:39 +0000 (GMT) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by lhreml701-cah.china.huawei.com (10.201.108.42) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 20 Feb 2020 10:52:39 +0000 Received: from [127.0.0.1] (10.202.226.45) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 20 Feb 2020 10:52:39 +0000 Subject: Re: Questions about logic_pio To: Wei Xu , Jiaxun Yang , bhelgaas , andyshevchenko CC: Arnd Bergmann , linux-kernel References: <1705dbe62ce.10ae800394772.9222265269135747883@flygoat.com> <5E4E55F7.70800@hisilicon.com> From: John Garry Message-ID: Date: Thu, 20 Feb 2020 10:52:38 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <5E4E55F7.70800@hisilicon.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.45] X-ClientProxiedBy: lhreml738-chm.china.huawei.com (10.201.108.188) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Arnd (also remove some defunct e-mail addresses) On 20/02/2020 09:48, Wei Xu wrote: > Hi Jiaxun, > > On 2020/2/19 21:58, Jiaxun Yang wrote: >> Hi there, >> >> Logic PIO gives us a way to make indirect PIO access, however, >> the way it handles direct (MMIO) I/O access confused me. >> >> I was trying to create a PCI controller Driver and noticed that I/O range parsed >> from DeviceTree will be added to the Logic PIO range by logic_pio_register_range. >> And than PCI subsystem will use the ioport obtained from `logic_pio_trans_cpuaddr` >> to allocate resources for the host bridge. In my case, the range added to the logic pio >> was set as hw_start 0x4000, size 0x4000. FYI, For when CONFIG_INDIRECT_PIO is defined, in logical PIO space, we reserve the last 0x4000 bytes for Indirectio, while the rest is available for MMIO. When CONFIG_INDIRECT_PIO is not defined, all Logical PIO space is available for MMIO. Later, `logic_pio_trans_cpuaddr` called >> by `pci_address_to_pio` gives a ioport of 0x0, which is totally wrong. ioport of 0x0 seems fine. Here is my IO port listing for my host (which defines PCI_IOBASE): 00000000-0000ffff : PCI Bus 0002:f8 00001000-00001fff : PCI Bus 0002:f9 00001000-00001007 : 0002:f9:00.0 00001000-00001007 : serial 00001008-0000100f : 0002:f9:00.1 00001008-0000100f : serial 00001010-00001017 : 0002:f9:00.2 00001018-0000101f : 0002:f9:00.2 00010000-0001ffff : PCI Bus 0004:88 00020000-0002ffff : PCI Bus 0005:78 00030000-0003ffff : PCI Bus 0006:c0 00040000-0004ffff : PCI Bus 0007:90 00050000-0005ffff : PCI Bus 000a:10 00060000-0006ffff : PCI Bus 000c:20 00070000-0007ffff : PCI Bus 000d:30 00ffc0e3-00ffc0e7 : hisi-lpc-ipmi.5.auto 00ffc2f7-00ffffff : serial8250.6.auto 00ffc2f7-00ffc2fe : serial >> >> After dig into logic pio logic, I found that logic pio is trying to "allocate" an io_start >> for MMIO ranges, the allocation starts from 0x0. And later the io_start is used to calculate >> cpu_address. In my opinion, for direct MMIO access, logic_pio address should always >> equal to hw address, I'm not sure what you mean by simply the hw address. So there is the physical cpu address of the host bridge IO ports, and these host bridge IO ports are mapped in pci_remap_iospace() to some part of logical PIO space. The base of the logical PIO space corresponds to PCI_IOBASE virtual address. because there is no way to translate address from logic pio address >> to actual hw address in {in,out}{b,sb,w,sb,l,sl} operations. Please check https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/logic_pio.c?h=v5.6-rc2#n231 for reference: #if defined(CONFIG_INDIRECT_PIO) && defined(PCI_IOBASE) #define BUILD_LOGIC_IO(bw, type) \ type logic_in##bw(unsigned long addr) \{ \ type ret = (type)~0; \ \ if (addr < MMIO_UPPER_LIMIT) { \ ret = read##bw(PCI_IOBASE + addr); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ if (entry) \ ret = entry->ops->in(entry->hostdata, \ addr, sizeof(type)); \ else \ WARN_ON_ONCE(1); \ } \ return ret; \} For when the IO port address is within the MMIO range (addr < MMIO_UPPER_LIMIT), we use readl(PCI_IOBASE + addr); please remember that PCI_IOBASE virtual address is mapped to the physical host bridge IO port address. For when CONFIG_INDIRECT_PIO is not defined, we use the asm generic version: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/asm-generic/io.h?h=v5.6-rc2#n461 As an aside, I do notice that the definitions here have changed here in 87fe2d543f81 ("io: change inX() to have their own IO barrier overrides") since we introduced logic PIO. >> >> How this mechanism intends to work? I hope the above description makes this clearer. What is the reason that we are trying to >> allocate a io_start for MMIO rather than take their hw_start ioport directly? For PCI MMIO, the io_start is the Logical PIO range start address. >> >> Thanks. > > Corrected John's mail address. > Maybe he can help. Thanks to xuwei > > Best Regards, > Wei > >> >> -- >> Jiaxun Yang >> >> >> >> . >> > > . >