ReactOS  0.4.13-dev-257-gfabbd7c
xboxmem.c File Reference
#include <freeldr.h>
Include dependency graph for xboxmem.c:

Go to the source code of this file.

Macros

#define TEST_SIZE   0x200
 
#define TEST_PATTERN1   0xaa
 
#define TEST_PATTERN2   0x55
 

Functions

VOID XboxMemInit (VOID)
 
PFREELDR_MEMORY_DESCRIPTOR XboxMemGetMemoryMap (ULONG *MemoryMapSize)
 
PVOID XboxMemReserveMemory (ULONG MbToReserve)
 

Variables

static ULONG InstalledMemoryMb = 0
 
static ULONG AvailableMemoryMb = 0
 
FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap [2]
 

Macro Definition Documentation

◆ TEST_PATTERN1

#define TEST_PATTERN1   0xaa

Definition at line 28 of file xboxmem.c.

◆ TEST_PATTERN2

#define TEST_PATTERN2   0x55

Definition at line 29 of file xboxmem.c.

◆ TEST_SIZE

#define TEST_SIZE   0x200

Definition at line 27 of file xboxmem.c.

Function Documentation

◆ XboxMemGetMemoryMap()

PFREELDR_MEMORY_DESCRIPTOR XboxMemGetMemoryMap ( ULONG MemoryMapSize)

Definition at line 80 of file xboxmem.c.

81 {
82  /* Synthesize memory map */
83  /* Available RAM block */
84  XboxMemoryMap[0].BasePage = 0;
85  XboxMemoryMap[0].PageCount = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE;
87 
88  /* Video memory */
89  XboxMemoryMap[1].BasePage = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE;
90  XboxMemoryMap[1].PageCount = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024 / MM_PAGE_SIZE;
92 
93  *MemoryMapSize = 2;
94  return XboxMemoryMap;
95 }
TYPE_OF_MEMORY MemoryType
Definition: mm.h:38
FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap[2]
Definition: xboxmem.c:77
static ULONG AvailableMemoryMb
Definition: xboxmem.c:25
PFN_NUMBER BasePage
Definition: mm.h:39
static ULONG InstalledMemoryMb
Definition: xboxmem.c:24
PFN_NUMBER PageCount
Definition: mm.h:40

Referenced by XboxMachInit().

◆ XboxMemInit()

VOID XboxMemInit ( VOID  )

Definition at line 32 of file xboxmem.c.

33 {
34  UCHAR ControlRegion[TEST_SIZE];
35  PVOID MembaseTop = (PVOID)(64 * 1024 * 1024);
36  PVOID MembaseLow = (PVOID)0;
37 
38  (*(PULONG)(0xfd000000 + 0x100200)) = 0x03070103 ;
39  (*(PULONG)(0xfd000000 + 0x100204)) = 0x11448000 ;
40 
41  WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
42  WRITE_PORT_ULONG((ULONG*) 0xcfc, 0x7ffffff); /* Prep hardware for 128 Mb */
43 
44  InstalledMemoryMb = 64;
45  memset(ControlRegion, TEST_PATTERN1, TEST_SIZE);
46  memset(MembaseTop, TEST_PATTERN1, TEST_SIZE);
47  __wbinvd();
48 
49  if (0 == memcmp(MembaseTop, ControlRegion, TEST_SIZE))
50  {
51  /* Looks like there is memory .. maybe a 128MB box */
52  memset(ControlRegion, TEST_PATTERN2, TEST_SIZE);
53  memset(MembaseTop, TEST_PATTERN2, TEST_SIZE);
54  __wbinvd();
55  if (0 == memcmp(MembaseTop, ControlRegion, TEST_SIZE))
56  {
57  /* Definitely looks like there is memory */
58  if (0 == memcmp(MembaseLow, ControlRegion, TEST_SIZE))
59  {
60  /* Hell, we find the Test-string at 0x0 too ! */
61  InstalledMemoryMb = 64;
62  }
63  else
64  {
65  InstalledMemoryMb = 128;
66  }
67  }
68  }
69 
70  /* Set hardware for amount of memory detected */
71  WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
72  WRITE_PORT_ULONG((ULONG*) 0xcfc, InstalledMemoryMb * 1024 * 1024 - 1);
73 
75 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define TEST_SIZE
Definition: xboxmem.c:27
static ULONG AvailableMemoryMb
Definition: xboxmem.c:25
#define TEST_PATTERN1
Definition: xboxmem.c:28
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
void * PVOID
Definition: retypes.h:9
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
unsigned char UCHAR
Definition: xmlstorage.h:181
#define TEST_PATTERN2
Definition: xboxmem.c:29
unsigned int * PULONG
Definition: retypes.h:1
#define CONFIG_CMD(bus, dev_fn, where)
Definition: hardware.h:23
static ULONG InstalledMemoryMb
Definition: xboxmem.c:24
unsigned int ULONG
Definition: retypes.h:1
#define memset(x, y, z)
Definition: compat.h:39

Referenced by XboxMachInit(), and XboxMemReserveMemory().

◆ XboxMemReserveMemory()

PVOID XboxMemReserveMemory ( ULONG  MbToReserve)

Definition at line 98 of file xboxmem.c.

99 {
100  if (0 == InstalledMemoryMb)
101  {
102  /* Hmm, seems we're not initialized yet */
103  XboxMemInit();
104  }
105 
106  if (AvailableMemoryMb < MbToReserve)
107  {
108  /* Can't satisfy the request */
109  return NULL;
110  }
111 
112  AvailableMemoryMb -= MbToReserve;
113 
114  /* Top of available memory points to the space just reserved */
115  return (PVOID) (AvailableMemoryMb * 1024 * 1024);
116 }
VOID XboxMemInit(VOID)
Definition: xboxmem.c:32
static ULONG AvailableMemoryMb
Definition: xboxmem.c:25
smooth NULL
Definition: ftsmooth.c:416
static ULONG InstalledMemoryMb
Definition: xboxmem.c:24

Referenced by XboxVideoInit().

Variable Documentation

◆ AvailableMemoryMb

ULONG AvailableMemoryMb = 0
static

Definition at line 25 of file xboxmem.c.

Referenced by XboxMemGetMemoryMap(), XboxMemInit(), and XboxMemReserveMemory().

◆ InstalledMemoryMb

ULONG InstalledMemoryMb = 0
static

Definition at line 24 of file xboxmem.c.

Referenced by XboxMemGetMemoryMap(), XboxMemInit(), and XboxMemReserveMemory().

◆ XboxMemoryMap

FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap[2]

Definition at line 77 of file xboxmem.c.

Referenced by XboxMemGetMemoryMap().