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=ard.biesheuvel@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 58488203BBB80 for ; Thu, 24 May 2018 07:54:27 -0700 (PDT) Received: by mail-it0-x241.google.com with SMTP id p3-v6so2735468itc.0 for ; Thu, 24 May 2018 07:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=lkrKdqCGqSWegO9J2X9lMY+uyyIvvKgDe8axxmw3JFU=; b=bLCpZKz0pheQtwXURaXLJ4wRRn9aT4LgZLPLz+4JFpAjBW6nfuvNN74I1LDcutj6Jg HvIgjd+bGwIjAmz8GaqTQ1E/5EnG46lY2DWiSBSX0WnvQKXahMik9AC4w2fPOSNAF97P BL5M1G37TRMyLPdemxt8GkrcZaLQjqe/AkjSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=lkrKdqCGqSWegO9J2X9lMY+uyyIvvKgDe8axxmw3JFU=; b=d2u7wy2eB+EGMNoYyGCBGSJNzsZtCkbLg1a1aWE3I3ddbm4FR0gCkoff4mHQoTw28/ zE3vc7Pi+L8HfjjDmoNX2sDhJ/w3HHhKPDY7E+jI7yqW8FKgRO66X1wTwgl3MhJQhaZD 2p/s3A8gO68WH3KlZZghjOivKSQyGRSjtQKiX38WZ4FNmnXzCDL0+0iXnYHMEegVqeyE ut603SQOQTgxBwEGo+dLYli9JqFCXA+ktGXVcqJ2eNCPP7O4k9RmXWcGaytzcuEleR+t /kCf0867X8D+cfBCvnAmabiWyq6rf0z3jS+y7NZpfSQVuUsNS+dZfHh12upmQRPD/wXq dkdg== X-Gm-Message-State: ALKqPweMizXYTfFxCPK3nxsOT4hycw6VQ0TIDNKCWwZqaG43G6cdDdFA HFFV50USdfrUm2n5OMOZ3JKCvSqshhW9B/h3Y72PKA== X-Google-Smtp-Source: AB8JxZoWJqN6MWsMh5G9gNYwi4tJbg0i++SoTlnAmM/IZVOavfiyazlxwYjAcgCMRGXR74/fVfuSfI/46Xt1nlia2jk= X-Received: by 2002:a24:5390:: with SMTP id n138-v6mr9378257itb.42.1527173666588; Thu, 24 May 2018 07:54:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bb86:0:0:0:0:0 with HTTP; Thu, 24 May 2018 07:54:26 -0700 (PDT) In-Reply-To: References: <20180523202121.8125-1-lersek@redhat.com> <20180523202121.8125-4-lersek@redhat.com> <1cef03f3-f3be-9fd6-2644-a16ec95f1949@redhat.com> From: Ard Biesheuvel Date: Thu, 24 May 2018 16:54:26 +0200 Message-ID: To: Laszlo Ersek Cc: edk2-devel-01 , Jordan Justen Subject: Re: [PATCH v2 3/7] OvmfPkg: introduce PciCapPciIoLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 May 2018 14:54:27 -0000 Content-Type: text/plain; charset="UTF-8" On 24 May 2018 at 16:54, Ard Biesheuvel wrote: > On 24 May 2018 at 16:50, Laszlo Ersek wrote: >> On 05/24/18 10:13, Ard Biesheuvel wrote: >>> On 23 May 2018 at 22:21, Laszlo Ersek wrote: >>>> Add a library class, and a UEFI_DRIVER lib instance, that are layered on >>>> top of PciCapLib, and allow clients to plug an EFI_PCI_IO_PROTOCOL backend >>>> into PciCapLib, for config space access. >>>> >>>> (Side note: >>>> >>> >>> Again, please retain the below. >> >> Will do. >> >>>> +STATIC >>>> +EFI_STATUS >>>> +ProtoDevTransferConfig ( >>>> + IN EFI_PCI_IO_PROTOCOL *PciIo, >>>> + IN EFI_PCI_IO_PROTOCOL_CONFIG TransferFunction, >>>> + IN UINT16 ConfigOffset, >>>> + IN OUT UINT8 *Buffer, >>>> + IN UINT16 Size >>>> + ) >>>> +{ >>>> + while (Size > 0) { >>>> + EFI_PCI_IO_PROTOCOL_WIDTH Width; >>>> + UINT16 Count; >>>> + EFI_STATUS Status; >>>> + UINT16 Progress; >>>> + >>>> + // >>>> + // Pick the largest access size that is allowed by the remaining transfer >>>> + // Size and by the alignment of ConfigOffset. >>>> + // >>>> + // When the largest access size is available, transfer as many bytes as >>>> + // possible in one iteration of the loop. Otherwise, transfer only one >>>> + // unit, to improve the alignment. >>>> + // >>>> + if (Size >= BIT2 && (ConfigOffset & (BIT2 - 1)) == 0) { >>> >>> Ugh. Just use '4' or sizeof(UINT32). >>> >>>> + Width = EfiPciIoWidthUint32; >>>> + Count = Size >> Width; >>>> + } else if (Size >= BIT1 && (ConfigOffset & (BIT1 - 1)) == 0) { >>>> + Width = EfiPciIoWidthUint16; >>>> + Count = 1; >>>> + } else { >>>> + Width = EfiPciIoWidthUint8; >>>> + Count = 1; >>>> + } >> >> I used "BITx" and "(BITx - 1)" for consistency, and because they seemed >> to convey the idea well (namely, shifting down the alignment). >> >> I'm fine replacing "BIT2" with "4", but then I believe I should also >> replace "(BIT2 - 1)" with "3". Similarly, replace "BIT1" with "2", and >> "(BIT1 -1)" with 1. >> >> Do you prefer the current code or the decimal constants? >> > > IMHO, BITx is for bitmasks, not for numerical constants. > > So yes, if you think (as do I) that sizeof(UINTnn) is too wordy, just > use the plain numbers please. With that, Reviewed-by: Ard Biesheuvel