Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp782398ybv; Thu, 20 Feb 2020 07:13:27 -0800 (PST) X-Google-Smtp-Source: APXvYqw2BR1kcjew2+51SLxAEy4U5e7Vwh3B0UfiHhJzSIQT7IZgvpMiLP/6/u71Lfcc0JBtEEaJ X-Received: by 2002:aca:acc4:: with SMTP id v187mr2441030oie.130.1582211607391; Thu, 20 Feb 2020 07:13:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582211607; cv=none; d=google.com; s=arc-20160816; b=hlYE0DLqA/t5KvG7h21nNfid0YNFLRM+xR5HPtbU4mcuhFcfaVh949/05fQ2w6uEC4 c1Bjb9RCEXMQKJC1PJDWE5f7jjtFoJmrNc+sAGHGH7tdeebDOh4Y+4KFYNTbQOxBtbQw ubBWRYfcT8dja8Gro8Yj5z0wr9lL89wXOTvOM4kLxpQCkNEpXQj4fEsPZCm/jXPLrXTj znqpD6m+ezCS5CkgmzXAU83+ETt85yDre2uhEQnlodOGyxZ0KZsAReqAvK4wV0+CimJ6 3PyLep9PKbKgbgbhdaXuguzYkl8RnVxkKBO7wAxuPR0YbdQx6bQ+ta6UfOtug/Q+R5ru piww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-transfer-encoding :mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:dkim-signature; bh=JRDtQsXpqUz7hsmkd0dK4lht0q0VWQmzqTzKRrMqjh0=; b=khf6bOFh92xjI4PUIQvJD5YGFIE1fH72260y/c1gooWeCvD3Gd1R8RQEk/67RvQZrx VMu8aThQ+q1wwjMnMK12XB/jh01rqSNxqsGVSwnRteCMvfqGtm+8AKmYbvFc/k4ec3/o 156L9Tsr0dtzP+43QXVGhO9+uOllSbrJT+ZVUVB3N7nvnP1cNM4Bsrb7iDq3Vx393Ngt 3lTcz5vI7P6f0uN+SHe/RLdp1JgI0svXfRznEFtlXVzs1BPFI9FRwnj5tAKi/9Zm3Yrg 8AHSwRq9XnCPU7hgIQxzr9Cl6Y02IBUPJU/YsxfFb10rbQOp+zLjg9TovpY8KeUvXBaD 2g3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flygoat.com header.s=mail header.b=EiurU6QK; 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=flygoat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si1918410otv.190.2020.02.20.07.13.15; Thu, 20 Feb 2020 07:13:27 -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=@flygoat.com header.s=mail header.b=EiurU6QK; 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=flygoat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728448AbgBTPNE (ORCPT + 99 others); Thu, 20 Feb 2020 10:13:04 -0500 Received: from sender3-op-o12.zoho.com.cn ([124.251.121.243]:17864 "EHLO sender3-op-o12.zoho.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728385AbgBTPNE (ORCPT ); Thu, 20 Feb 2020 10:13:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1582211542; s=mail; d=flygoat.com; i=jiaxun.yang@flygoat.com; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=JRDtQsXpqUz7hsmkd0dK4lht0q0VWQmzqTzKRrMqjh0=; b=EiurU6QK7jrqxanpBh2gS4bNHic3BztEaU/5KGB0lhv34MlDO5zaLfXfp1PiZj5K oY/agn/b6K3fTACSKyRC7saahG3KzslxxSK4rOe4WEfcT9DBSlDCoLKtmVF4ac2OOlK TGcDsYxdHabxhFeBtPLUAig4WusYdUxW3I7sepgg= Received: from mail.baihui.com by mx.zoho.com.cn with SMTP id 1582211539685705.7136605582543; Thu, 20 Feb 2020 23:12:19 +0800 (CST) Date: Thu, 20 Feb 2020 23:12:19 +0800 From: Jiaxun Yang To: "John Garry" Cc: "Wei Xu" , "bhelgaas" , "andyshevchenko" , "Arnd Bergmann" , "linux-kernel" , "Linux Mips" Message-ID: <170632822e1.12fede49a6919.5706082545515934736@flygoat.com> In-Reply-To: <1ebf4461-eb37-ff58-1faf-dd24d83f85cf@huawei.com> References: <1705dbe62ce.10ae800394772.9222265269135747883@flygoat.com> <5E4E55F7.70800@hisilicon.com> <17062738bc0.c380503c6222.6801557833645076299@flygoat.com> <1ebf4461-eb37-ff58-1faf-dd24d83f85cf@huawei.com> Subject: Re: Questions about logic_pio MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Priority: Medium User-Agent: ZohoCN Mail X-Mailer: ZohoCN Mail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ---- =E5=9C=A8 =E6=98=9F=E6=9C=9F=E5=9B=9B, 2020-02-20 22:23:57 John Garry= =E6=92=B0=E5=86=99 ---- > > Also Cc MIPS list to check other's opinions. > >=20 > > Hi John. > >=20 >=20 > Hi Jiaxun Yang, >=20 > > Thanks for your kind explanation, however, I think this way is > > violating how I/O ports supposed to work, at least in MIPS world. >=20 > For a bit more history, please understand that the core PCI code was=20 > managing non-native IO port space in the same way before we added the=20 > logic PIO framework. The only real functional change here was that we=20 > introduced the indirect-io region within the IO port space, under=20 > CONFIG_INDIRECT_PIO. I'm going to do more investigation. Thanks.=20 >=20 > >=20 > > > >> > > > >> After dig into logic pio logic, I found that logic pio is tryin= g 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. > > > > >=20 > > I meant hw_start should always equal to io_start. > >=20 > >=20 > > MIPS have their own wrapped inl/outl functions,=20 >=20 > Can you please point me to these? I could not find them in arch/mips They are built by __BUILD_IOPORT_PFX(bus, bwlq, type) macro. Just using mips_io_port_base + offset to handle inl/outl, the same way PCI_= IOBASE. >=20 > I will also note that arch/mips/include/asm/io.h does not include=20 > asm-generic io.h today Yes, and I'm attempting to take advantage of asm-generic. >=20 > doing the samething with > > PCI_IOBASE enabled one. I was just trying to use PCI_IOBASE instead. > >=20 > > Originally, the I/O ports layout seems like this: > >=20 > > 00000020-00000021 : pic1 > > 00000060-0000006f : i8042 > > 00000070-00000077 : rtc0 > > 000000a0-000000a1 : pic2 > > 00000170-00000177 : pata_atiixp > > 000001f0-000001f7 : pata_atiixp > > 00000376-00000376 : pata_atiixp > > 000003f6-000003f6 : pata_atiixp > > 00000800-000008ff : acpi > > 00001000-00001008 : piix4_smbus > > 00004000-0003ffff : pci io space > > 00004000-00004fff : PCI Bus 0000:01 > > 00004000-000040ff : 0000:01:05.0 > > 00005000-00005fff : PCI Bus 0000:03 > > 00005000-0000501f : 0000:03:00.0 > >=20 > > But with PCI_IOBASE defined, I got this: > >=20 > > host bridge /bus@10000000/pci@10000000 ranges: > > MEM 0x0040000000..0x007fffffff -> 0x0040000000 > > IO 0x0000004000..0x0000007fff -> 0x0000004000 > > resource collision: [io 0x0000-0x3fff] conflicts with pic1 [io 0x002= 0-0x0021] > >=20 > > Because io_start was allocated to 0x0 by Logic PIO. > >=20 > > There are a lot of devices that have fixed ioports thanks to x86's leg= acy. >=20 > Well, yes, I'm not so surprised. >=20 > So if MIPS does not have native IO port access, then surely you need=20 > some host bridge to translate host CPU MMIO accesses to port I/O=20 > accesses, right? Where are these CPU addresses defined? It is defined by the variable mips_io_port_base. >=20 > > For example, in my hardware, ioports for RTC, PIC, I8042 are unmoveabl= e, > > and they can't be managed by logic pio subsystem. > Also, the PCI Host= bridge got implied by DeviceTree that it's I/O range > > started from 0x4000 in bus side >=20 > which bus is this? They're all located under "ISA Range". Just an MMIO range that will resend the request to ISA I/O. --ioports for both PCI and some legacy devices. In that range, base + 0x0000 to 0x4000 is preserved for PIO devices (e.g.) = I8259 and base + 0x4000 to MMIO_LIMIT are for PCI devices under host bridge. For the host bridge, ioports it can decode starts from 0x4000. My intentional behavior is that when I'm specifying in dts that the IO Rang= e of PCI host bridge is 0x4000 to 0x7fff, it would request the IO_RESOURCE start from 0x4= 000 to 0x7fff, also tell the host driver to decode 0x4000 to 0x7fff in IO BAR,= And let the drivers access 0x4000 to 0x7fff via inl/outl, rather than allocate from PIO 0x0 to = 0x3fff. >=20 > , but then, Logic PIO remapped to PCI_IOBASE + 0x0. > > The real address should be PCI_IOBASE + 0x4000, >=20 > You seem to be using two methods to manage IO port space, and they seem= =20 > to be conflicting. So... Are there any way to handle these unmoveable devices in logic pio wor= ld? >=20 > > hardware never got correctly informed about that. And there is still n= o way to > > transform to correct address as it's inside the MMIO_LIMIT. > >=20 > > So the question comes to why we're allocating io_start for MMIO PCI_IO= BASE > > rather than just check the range provided doesn't overlap each other o= r exceed > > the MMIO_LIMIT. >=20 > When PCI_IOBASE is defined, we work on the basis that any IO port range= =20 > in the system is registered for a logical PIO region, which manages the= =20 > actual IO port addresses - see logic_pio_trans_cpuaddr(). The port is not the actual port.. It makes me confusing about what it's act= ually doing.. Sorry but probably I'm still thinking in a vintage way -- need some hints a= bout how to deal with these legacy cases in a modern way. Thanks. >=20 > Thanks, > John >