public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, kraxel@redhat.com
Cc: Oliver Steffen <osteffen@redhat.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>
Subject: Re: [edk2-devel] [PATCH 2/3] OvmfPkg/PlatformPei: rewrite page table calculation
Date: Wed, 31 Jan 2024 16:21:26 +0100	[thread overview]
Message-ID: <74ccb355-7d71-150b-7258-305149699c0d@redhat.com> (raw)
In-Reply-To: <cbe72962-0562-e776-b80e-e4a3762df558@redhat.com>

On 1/31/24 16:13, Laszlo Ersek wrote:

> (3) I'm sorry, these +1 additions *really* annoy me, not to mention the
> fact that we *include* those increments in the further shifting. Can we do:
> 
>   UINT64  End;
>   UINT64  Level2Pages, Level3Pages, Level4Pages, Level5Pages;
> 
>   End         = 1LLU << PlatformInfoHob->PhysMemAddressWidth;
>   Level2Pages = Page1GSupport ? 0LLU : End >> 30;
>   Level3Pages = MAX (End >> 39, 1LLU);
>   Level4Pages = MAX (End >> 48, 1LLU);
>   Level5Pages = 1;
> 
> This doesn't seem any more complicated, and it's exact, I believe.

Sorry, I forgot about an edk2 portability rule here. We shouldn't do
64-bit wide "native" shifts in code that may be compiled for 32-bit.
Instead, we're supposed to use LShiftU64() and RShiftU64(), from
BaseLib. Thus:

  UINT64  End;
  UINT64  Level2Pages, Level3Pages, Level4Pages, Level5Pages;

  End         = LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth);
  Level2Pages = Page1GSupport ? 0LLU : RShiftU64 (End, 30);
  Level3Pages = MAX (RShiftU64 (End, 39), 1LLU);
  Level4Pages = MAX (RShiftU64 (End, 48), 1LLU);
  Level5Pages = 1;

Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114906): https://edk2.groups.io/g/devel/message/114906
Mute This Topic: https://groups.io/mt/104073300/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-01-31 15:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 11:59 [edk2-devel] [PATCH 0/3] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
2024-01-31 11:59 ` [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap Gerd Hoffmann
2024-01-31 14:08   ` Laszlo Ersek
2024-01-31 14:55     ` Gerd Hoffmann
2024-01-31 19:29       ` Laszlo Ersek
2024-01-31 11:59 ` [edk2-devel] [PATCH 2/3] OvmfPkg/PlatformPei: rewrite page table calculation Gerd Hoffmann
2024-01-31 15:13   ` Laszlo Ersek
2024-01-31 15:21     ` Laszlo Ersek [this message]
2024-01-31 16:28     ` Gerd Hoffmann
2024-02-01 21:04       ` Laszlo Ersek
2024-01-31 12:00 ` [edk2-devel] [PATCH 3/3] OvmfPkg/PlatformPei: log pei memory cap details Gerd Hoffmann
2024-01-31 15:38   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74ccb355-7d71-150b-7258-305149699c0d@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox