From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::343; helo=mail-wm1-x343.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 6519121959CB2 for ; Fri, 9 Nov 2018 05:34:20 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id f19-v6so3807121wmb.0 for ; Fri, 09 Nov 2018 05:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=x0fLVw8m9PmW+vCtV10ZLLzDR5GVnSvG0xz9qZZ0nxE=; b=PF6RbxMH95c2nScaw3kwWthWzXl4u8uVtU0655TUbB/YWTPFuR6yOYzxfjuCTyh1CO xfTKsjNWpqSqlV6K4JMlscpiBHPXfA/fgfaKu0Turzb+0FaiCgugfVahCvkZZJkJm0g7 TvAgSNvYvBYV9w2evnulpcHLCciXM+Bx/H2zI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=x0fLVw8m9PmW+vCtV10ZLLzDR5GVnSvG0xz9qZZ0nxE=; b=K2MvWwlOY6fzuDxWVpX4n3j3ODzw72BrZq8i8DqAqW2XwYxVQ8h+D8TKvrPKG4/8Wl KaWPKqwutBGbN6ctI+0C6DCjVpQ/wLRw8eIRo/wx3cQCONWoU83a4s0JL8m4oxtU3T/p Tf/UckpIpr3HdW9hpQSyMGwlqtu2DWhxCuMzalFej0GRzfjv1cWVSzH834ElbArqERBy 7WH4i6DPdco9DeP+tId7Rkmg20neE1ytzf1EOvNh2da/WUp+3Jn0kBJKy+CgqPz4jtzf LF7qS16GwJRgkHj+3477bmrKRIxVXiHqMQ29xJDpqf6loECjYqdsBANX0c/GkjeD0PRg 2tGQ== X-Gm-Message-State: AGRZ1gITysW1UtKU5TSktFSCX6aOF88cgBQsG+zdPkReAxEdbWw5aNMb 4MCjIJYKNHOGCoWK1sJLUgoVEg== X-Google-Smtp-Source: AJdET5eZUMAySfD+oY2Y2rCN6GqbZG1/m4hlSShvqWaqBI2iolx6flzsjZH12DpWEGjgzrcZOr++KA== X-Received: by 2002:a7b:cd87:: with SMTP id y7-v6mr2105789wmj.110.1541770457975; Fri, 09 Nov 2018 05:34:17 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id o81-v6sm1594407wmo.38.2018.11.09.05.34.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Nov 2018 05:34:17 -0800 (PST) Date: Fri, 9 Nov 2018 13:34:15 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20181109133415.z75x5qg2dgd4egw3@bivouac.eciton.net> References: <20181109075848.12029-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20181109075848.12029-1-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH v2 edk2-platforms] Silicon/SynQuacerPciCpuIo2Dxe: fix PCIe I/O translation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Nov 2018 13:34:21 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Nov 09, 2018 at 08:58:48AM +0100, Ard Biesheuvel wrote: > Commit 9dd8190e4995 ("Silicon/SynQuacer: tweak PCI I/O windows for > ACPI/Linux support") updated the min/max/offset definitions for the > PCIe I/O resource windows on SynQuacer, and updated the read path of > the platform's EfiCpuIo2 protocol implementation, but failed to update > the write path as well, resulting in spurious errors if when attempting > to write to PCIe I/O ports on PCIe RC #1, which uses translation for the > I/O BAR window. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Much neater, thank you. Reviewed-by: Leif Lindholm > --- > v2: use helper function and temp vars > > Silicon/Socionext/SynQuacer/Drivers/SynQuacerPciCpuIo2Dxe/SynQuacerPciCpuIo2Dxe.c | 62 ++++++++++++-------- > 1 file changed, 37 insertions(+), 26 deletions(-) > > diff --git a/Silicon/Socionext/SynQuacer/Drivers/SynQuacerPciCpuIo2Dxe/SynQuacerPciCpuIo2Dxe.c b/Silicon/Socionext/SynQuacer/Drivers/SynQuacerPciCpuIo2Dxe/SynQuacerPciCpuIo2Dxe.c > index 736b20cd5129..049657231cab 100644 > --- a/Silicon/Socionext/SynQuacer/Drivers/SynQuacerPciCpuIo2Dxe/SynQuacerPciCpuIo2Dxe.c > +++ b/Silicon/Socionext/SynQuacer/Drivers/SynQuacerPciCpuIo2Dxe/SynQuacerPciCpuIo2Dxe.c > @@ -354,6 +354,37 @@ CpuMemoryServiceWrite ( > return EFI_SUCCESS; > } > > +STATIC > +EFI_STATUS > +TranslateIoAddress ( > + IN OUT UINT64 *Address > + ) > +{ > + UINT64 Start; > + UINT64 End; > + UINT64 Shift; > + > + Start = SYNQUACER_PCI_SEG0_PORTIO_MIN + SYNQUACER_PCI_SEG0_PORTIO_OFFSET; > + End = SYNQUACER_PCI_SEG0_PORTIO_MAX + SYNQUACER_PCI_SEG0_PORTIO_OFFSET; > + Shift = SYNQUACER_PCI_SEG0_PORTIO_MEMBASE - SYNQUACER_PCI_SEG0_PORTIO_OFFSET; > + > + if (*Address >= Start && *Address <= End) { > + *Address += Shift; > + return EFI_SUCCESS; > + } > + > + Start = SYNQUACER_PCI_SEG1_PORTIO_MIN + SYNQUACER_PCI_SEG1_PORTIO_OFFSET; > + End = SYNQUACER_PCI_SEG1_PORTIO_MAX + SYNQUACER_PCI_SEG1_PORTIO_OFFSET; > + Shift = SYNQUACER_PCI_SEG1_PORTIO_MEMBASE - SYNQUACER_PCI_SEG1_PORTIO_OFFSET; > + > + if (*Address >= Start && *Address <= End) { > + *Address += Shift; > + return EFI_SUCCESS; > + } > + ASSERT (FALSE); > + return EFI_INVALID_PARAMETER; > +} > + > /** > Reads I/O registers. > > @@ -415,22 +445,9 @@ CpuIoServiceRead ( > return Status; > } > > - if ((Address >= (SYNQUACER_PCI_SEG0_PORTIO_MIN + > - SYNQUACER_PCI_SEG0_PORTIO_OFFSET)) && > - (Address <= (SYNQUACER_PCI_SEG0_PORTIO_MAX + > - SYNQUACER_PCI_SEG0_PORTIO_OFFSET))) { > - Address += SYNQUACER_PCI_SEG0_PORTIO_MEMBASE - > - SYNQUACER_PCI_SEG0_PORTIO_OFFSET; > - } else if ((Address >= (SYNQUACER_PCI_SEG1_PORTIO_MIN + > - SYNQUACER_PCI_SEG1_PORTIO_OFFSET)) && > - (Address <= (SYNQUACER_PCI_SEG1_PORTIO_MAX + > - SYNQUACER_PCI_SEG1_PORTIO_OFFSET))) { > - Address += SYNQUACER_PCI_SEG1_PORTIO_MEMBASE - > - SYNQUACER_PCI_SEG1_PORTIO_OFFSET; > - > - } else { > - ASSERT (FALSE); > - return EFI_INVALID_PARAMETER; > + Status = TranslateIoAddress (&Address); > + if (EFI_ERROR (Status)) { > + return Status; > } > > // > @@ -518,16 +535,9 @@ CpuIoServiceWrite ( > return Status; > } > > - if ((Address >= SYNQUACER_PCI_SEG0_PORTIO_MIN) && > - (Address <= SYNQUACER_PCI_SEG0_PORTIO_MAX)) { > - Address += SYNQUACER_PCI_SEG0_PORTIO_MEMBASE; > - } else if ((Address >= SYNQUACER_PCI_SEG1_PORTIO_MIN) && > - (Address <= SYNQUACER_PCI_SEG1_PORTIO_MAX)) { > - Address += SYNQUACER_PCI_SEG1_PORTIO_MEMBASE; > - > - } else { > - ASSERT (FALSE); > - return EFI_INVALID_PARAMETER; > + Status = TranslateIoAddress (&Address); > + if (EFI_ERROR (Status)) { > + return Status; > } > > // > -- > 2.19.1 >