https://git.reactos.org/?p=reactos.git;a=commitdiff;h=034820ca552437db68079…
commit 034820ca552437db68079f5d23b078262183bece
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Wed Oct 9 03:35:07 2019 +0300
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Oct 9 02:35:07 2019 +0200
[FREELDR] Xbox memory management improvements (#1961)
- Reuse the framebuffer address that was set up by the firmware.
- Get rid of XboxMemReserveMemory() and use ReserveMemory() instead.
CORE-16216
---
boot/freeldr/freeldr/arch/i386/xboxmem.c | 48 +++++++++--------------
boot/freeldr/freeldr/arch/i386/xboxvideo.c | 15 ++++---
boot/freeldr/freeldr/include/arch/i386/machxbox.h | 1 -
3 files changed, 29 insertions(+), 35 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/i386/xboxmem.c
b/boot/freeldr/freeldr/arch/i386/xboxmem.c
index 2d6890ea78e..bf7721dc32c 100644
--- a/boot/freeldr/freeldr/arch/i386/xboxmem.c
+++ b/boot/freeldr/freeldr/arch/i386/xboxmem.c
@@ -26,6 +26,8 @@ DBG_DEFAULT_CHANNEL(MEMORY);
static ULONG InstalledMemoryMb = 0;
static ULONG AvailableMemoryMb = 0;
+extern PVOID FrameBuffer;
+extern ULONG FrameBufferSize;
#define TEST_SIZE 0x200
#define TEST_PATTERN1 0xAA
@@ -38,6 +40,14 @@ SetMemory(
SIZE_T Size,
TYPE_OF_MEMORY MemoryType);
+extern VOID
+ReserveMemory(
+ PFREELDR_MEMORY_DESCRIPTOR MemoryMap,
+ ULONG_PTR BaseAddress,
+ SIZE_T Size,
+ TYPE_OF_MEMORY MemoryType,
+ PCHAR Usage);
+
extern ULONG
PcMemFinalizeMemoryMap(
PFREELDR_MEMORY_DESCRIPTOR MemoryMap);
@@ -85,7 +95,6 @@ XboxMemInit(VOID)
WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
WRITE_PORT_ULONG((ULONG*) 0xcfc, InstalledMemoryMb * 1024 * 1024 - 1);
- /* 4 MB video framebuffer is reserved later using XboxMemReserveMemory() */
AvailableMemoryMb = InstalledMemoryMb;
}
@@ -105,37 +114,18 @@ XboxMemGetMemoryMap(ULONG *MemoryMapSize)
AvailableMemoryMb * 1024 * 1024,
LoaderFree);
- /* Video memory */
- SetMemory(XboxMemoryMap,
- AvailableMemoryMb * 1024 * 1024,
- (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024,
- LoaderFirmwarePermanent);
-
- *MemoryMapSize = PcMemFinalizeMemoryMap(XboxMemoryMap);
- return XboxMemoryMap;
-}
-
-PVOID
-XboxMemReserveMemory(ULONG MbToReserve)
-{
- /* This function is used to reserve video framebuffer in XboxVideoInit() */
-
- if (InstalledMemoryMb == 0)
- {
- /* Hmm, seems we're not initialized yet */
- XboxMemInit();
- }
-
- if (MbToReserve > AvailableMemoryMb)
+ if (FrameBufferSize != 0)
{
- /* Can't satisfy the request */
- return NULL;
+ /* Video memory */
+ ReserveMemory(XboxMemoryMap,
+ (ULONG_PTR)FrameBuffer,
+ FrameBufferSize,
+ LoaderFirmwarePermanent,
+ "Video memory");
}
- AvailableMemoryMb -= MbToReserve;
-
- /* Top of available memory points to the space just reserved */
- return (PVOID)(AvailableMemoryMb * 1024 * 1024);
+ *MemoryMapSize = PcMemFinalizeMemoryMap(XboxMemoryMap);
+ return XboxMemoryMap;
}
/* EOF */
diff --git a/boot/freeldr/freeldr/arch/i386/xboxvideo.c
b/boot/freeldr/freeldr/arch/i386/xboxvideo.c
index bcb70d0ce10..c664eef5d3c 100644
--- a/boot/freeldr/freeldr/arch/i386/xboxvideo.c
+++ b/boot/freeldr/freeldr/arch/i386/xboxvideo.c
@@ -24,7 +24,8 @@
DBG_DEFAULT_CHANNEL(UI);
-static PVOID FrameBuffer;
+PVOID FrameBuffer;
+ULONG FrameBufferSize;
static ULONG ScreenWidth;
static ULONG ScreenHeight;
static ULONG BytesPerPixel;
@@ -126,8 +127,15 @@ XboxVideoInit(VOID)
{
ULONG AvMode;
- FrameBuffer = (PVOID)((ULONG) XboxMemReserveMemory(FB_SIZE_MB) | 0xf0000000);
+ /* Reuse framebuffer that was set up by firmware */
+ FrameBuffer = (PVOID)*((PULONG) 0xfd600800);
+ /* Verify that framebuffer address is page-aligned */
+ ASSERT((ULONG_PTR)FrameBuffer % PAGE_SIZE == 0);
+ /* FIXME: obtain fb size from firmware somehow (Cromwell reserves high 4 MB of RAM) */
+ FrameBufferSize = 4 * 1024 * 1024;
+
+ /* FIXME: don't use SMBus, obtain current video resolution directly from NV2A */
if (I2CTransmitByteGetReturn(0x10, 0x04, &AvMode))
{
if (1 == AvMode) /* HDTV */
@@ -157,9 +165,6 @@ XboxVideoInit(VOID)
Delta = (ScreenWidth * BytesPerPixel + 3) & ~ 0x3;
XboxVideoClearScreenColor(MAKE_COLOR(0, 0, 0), TRUE);
-
- /* Tell the nVidia controller about the framebuffer */
- *((PULONG) 0xfd600800) = (ULONG) FrameBuffer;
}
VIDEODISPLAYMODE
diff --git a/boot/freeldr/freeldr/include/arch/i386/machxbox.h
b/boot/freeldr/freeldr/include/arch/i386/machxbox.h
index f481bbde8f9..393f3a900e2 100644
--- a/boot/freeldr/freeldr/include/arch/i386/machxbox.h
+++ b/boot/freeldr/freeldr/include/arch/i386/machxbox.h
@@ -63,7 +63,6 @@ VOID XboxVideoPrepareForReactOS(VOID);
VOID XboxPrepareForReactOS(VOID);
VOID XboxMemInit(VOID);
-PVOID XboxMemReserveMemory(ULONG MbToReserve);
PFREELDR_MEMORY_DESCRIPTOR XboxMemGetMemoryMap(ULONG *MemoryMapSize);
BOOLEAN XboxDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG
SectorCount, PVOID Buffer);