From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::241; helo=mail-it0-x241.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x241.google.com (mail-it0-x241.google.com [IPv6:2607:f8b0:4001:c0b::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4590B22198F44 for ; Thu, 21 Dec 2017 03:27:57 -0800 (PST) Received: by mail-it0-x241.google.com with SMTP id u62so10330300ita.2 for ; Thu, 21 Dec 2017 03:32:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ANyjo3wg1NFEXkcF4v4l73wm6mrGxWtfV+kfHzniOHg=; b=auhdeIqfy0XAUc3QdATv83rwVJVaP666z3Y5hZXOt+KHA8BQBVRiI4liBed3s/SBro wnWfCaeJS1LxcGcjDQF/pGcbwQFZeKDUh5NVqvlQV5Y6+hbcmLi/SzRWHjneLB8j+vwg 2bgwLq1Xb3IIigFFjxXW/zF0yUZooLEfI9QlQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ANyjo3wg1NFEXkcF4v4l73wm6mrGxWtfV+kfHzniOHg=; b=JOP7Q9WgvSjEXKF6C42lzGnX2njDyVTvxul6TFSDQ6A3brSJu5fQikyTHINoiHALCe j0s+zY/y0czFSv3/U9/aXZ8h6ovX2aph9I+sgFN8Q44mYKyYB18VbaLwnKtLDmy8Vb4G U/mv0zQXCBdYPHynv8MMStCvXptMPWrofexVmPX5VJf4bJU1D7rRYRh2a4MkUCihCqdO NDmMrYwox4Okk2FZpGmzKus3IENDdAjAypFs+w/w+c3IfPYMfJjAVT866uejtGu16O7Q pTUnwSkHv5zjn4OAz1MjuNnHB9gmaM5o/yi6mI3CtYy+UJb7/DJ3FlUZ44dmqwvxHurf Za/w== X-Gm-Message-State: AKGB3mJ/YA18JRDRPg/BafbpZUwP77sAvy6aQkKrdVRY0glGa6MECwut Rh94qQLeLIrnYi33T6xqDcVZcQ== X-Google-Smtp-Source: ACJfBov1wyJK6tKJSjy2he7tBDPbik+how1LmPRrNl7PJkbUWGfb0uVH5gJGU3thuM/pVG89jEfJnQ== X-Received: by 10.36.105.65 with SMTP id e62mr13428055itc.6.1513855965934; Thu, 21 Dec 2017 03:32:45 -0800 (PST) Received: from SZX1000114654 ([45.56.152.249]) by smtp.gmail.com with ESMTPSA id z74sm10049514iod.61.2017.12.21.03.32.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2017 03:32:44 -0800 (PST) From: Guo Heyi X-Google-Original-From: Guo Heyi Date: Thu, 21 Dec 2017 19:32:39 +0800 To: "Ni, Ruiyu" Cc: Ard Biesheuvel , gary guo , linaro-uefi , "edk2-devel@lists.01.org" , "Zeng, Star" , "Dong, Eric" , Jason Zhang Message-ID: <20171221113239.GC100076@SZX1000114654> References: <1513758078-99534-1-git-send-email-heyi.guo@linaro.org> <20171220151704.GA2482@iwish> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Subject: Re: [RFC] MdeModulePkg/PciHostBridge: Add address translation support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Dec 2017 11:27:58 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Dec 21, 2017 at 05:43:17PM +0800, Ni, Ruiyu wrote: > On 12/20/2017 11:26 PM, Ard Biesheuvel wrote: > >On 20 December 2017 at 15:17, gary guo wrote: > >>On Wed, Dec 20, 2017 at 09:13:58AM +0000, Ard Biesheuvel wrote: > >>>Hi Heyi, > >>> > >>>On 20 December 2017 at 08:21, Heyi Guo wrote: > >>>>PCIe on some ARM platforms requires address translation, not only for > >>>>legacy IO access, but also for 32bit memory BAR access as well. There > >>>>will be "Address Translation Unit" or something similar in PCI host > >>>>bridges to translation CPU address to PCI address and vice versa. So > >>>>we think it may be useful to add address translation support to the > >>>>generic PCI host bridge driver. > >>>> > >>> > >>>I agree. While unusual on a PC, it is quite common on other > >>>architectures to have more complex non 1:1 topologies, which currently > >>>require a forked PciHostBridgeDxe driver with local changes applied. > >>> > >>>>This RFC only contains one minor change to the definition of > >>>>PciHostBridgeLib, and there certainly will be a lot of other changes > >>>>to make it work, including: > >>>> > >>>>1. Use CPU address for GCD space add and allocate operations, instead > >>>>of PCI address; also IO space will be changed to memory space if > >>>>translation exists. > >>>> > >>> > >>>For I/O space, the translation should simply be applied to the I/O > >>>range. I don't think it makes sense to use memory space here, given > >>>that it is specific to architectures that lack native port I/O. > >>> > >> > >>I made an assumption here that platforms supporting real port IO space > >>do not need address translation, like IA32 and X64, and port IO > >>translation implies the platform does not support real port IO space. > >> > > > >This may be a reasonable assumption. But I still think it is better > >not to encode any assumptions in the first place. > > > >>Indeed the assumption is not so "generic", so I'll agree if you > >>recommend to support IO to IO translation as well. But I still hope to > >>have IO to memory translation support in PCI host bridge driver, > >>rather than in CPU IO protocol, since the faked IO space might only be > >>used for PCI host bridge and we may have overlapping IO ranges for > >>each host bridge, which is compatible with PCIe specification and PCIe > >>ACPI description. > >> > > > >That is fine. Under UEFI, these will translate to non-overlapping I/O > >spaces in the CPU's view. Under the OS, this could be totally > >different. > > > > I fully agree with the PciRootBridgeLib interface change to support > MMIO offset. I guess that you will propose to add a > AddrTranslationOffset to PCI_ROOT_BRIDGE structure. > > But I don't quite understand the needs of IO offset support. > > And further more, there was a discussion in the mailing list > regarding how to utilize the Offset. There was 2 points > about the meaning of Offset and we cannot agree with each > other. Spec is not quite clear. > 1. Offset = Host - Device > 2. Offset = Device - Host On our platforms, we use the 1st one and it seems Linux works well with it. And I think normally we will translate high CPU address into low PCI address (less than 4G) to make it compatible with some old PCIe devices, and in this scenario Offset will always be positive. Thanks, Gary > > > > > >For example, > > > >RC0 IO 0x0000 .. 0xffff -> CPU 0x00000 .. 0x0ffff > >RC1 IO 0x0000 .. 0xffff -> CPU 0x10000 .. 0x1ffff > > > >This is very similar to how MMIO translation works, and makes I/O > >devices behind the host bridges uniquely addressable for drivers. > > > >For our understanding, could you share the host bridge configuration > >that you are targetting? > > > >Thanks, > >Ard. > > > > > >>How about adding a flag to indicate whether port IO is translated to > >>real port IO space or system memory space? > >> > >>Thanks and regards, > >> > >>Heyi > >> > >>>>2. RootBridgeIoMemRead/Write, RootBridgeIoRead/Write need to get > >>>>translation of the corresponding aperture, add the translation to the > >>>>input address, and then call CpuIo2 protocol; IO access will also be > >>>>converted to memory access if IO translation exists. > >>>> > >>> > >>>Again, why is this necessary? A host bridge that implements a non 1:1 > >>>translation for port I/O ranges may be part of a system that has > >>>native port I/O, and so the translation should be based on that. > >>> > >>>>3. RootBridgeIoConfiguration needs to fill AddrTranslationOffset in > >>>>the discriptor. > >>>> > >>> > >>>Indeed. Note that this has been a source of much confusion lately, > >>>should we should discuss this carefully before spending time on an > >>>implementation. > >>> > >>>>If it makes sense, then I'll continue to prepare the formal patch. > >>>> > >>>>Any comments? > >>>> > >>>>Thanks, > >>>> > >>>>Gary (Heyi Guo) > >>>> > >>>>Cc: Star Zeng > >>>>Cc: Eric Dong > >>>>Cc: Ruiyu Ni > >>>>Cc: Ard Biesheuvel > >>>>Cc: Jason Zhang > >>>> > >>>>--- > >>>> MdeModulePkg/Include/Library/PciHostBridgeLib.h | 1 + > >>>> 1 file changed, 1 insertion(+) > >>>> > >>>>diff --git a/MdeModulePkg/Include/Library/PciHostBridgeLib.h b/MdeModulePkg/Include/Library/PciHostBridgeLib.h > >>>>index d42e9ec..b9e8c0f 100644 > >>>>--- a/MdeModulePkg/Include/Library/PciHostBridgeLib.h > >>>>+++ b/MdeModulePkg/Include/Library/PciHostBridgeLib.h > >>>>@@ -22,6 +22,7 @@ > >>>> typedef struct { > >>>> UINT64 Base; > >>>> UINT64 Limit; > >>>>+ UINT64 Translation; > >>>> } PCI_ROOT_BRIDGE_APERTURE; > >>>> > >>>> typedef struct { > >>>>-- > >>>>2.7.4 > >>>> > > > -- > Thanks, > Ray