4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Note: much of this code was based on knowledge and/or code developed
19 * by the Xbox Linux group: http://www.xbox-linux.org
25 DBG_DEFAULT_CHANNEL(MEMORY
);
27 static ULONG InstalledMemoryMb
= 0;
28 static ULONG AvailableMemoryMb
= 0;
30 #define TEST_SIZE 0x200
31 #define TEST_PATTERN1 0xAA
32 #define TEST_PATTERN2 0x55
36 PFREELDR_MEMORY_DESCRIPTOR MemoryMap
,
37 ULONG_PTR BaseAddress
,
39 TYPE_OF_MEMORY MemoryType
);
42 PcMemFinalizeMemoryMap(
43 PFREELDR_MEMORY_DESCRIPTOR MemoryMap
);
48 UCHAR ControlRegion
[TEST_SIZE
];
49 PVOID MembaseTop
= (PVOID
)(64 * 1024 * 1024);
50 PVOID MembaseLow
= (PVOID
)0;
52 (*(PULONG
)(0xfd000000 + 0x100200)) = 0x03070103;
53 (*(PULONG
)(0xfd000000 + 0x100204)) = 0x11448000;
55 WRITE_PORT_ULONG((ULONG
*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
56 WRITE_PORT_ULONG((ULONG
*) 0xcfc, 0x7ffffff); /* Prep hardware for 128 Mb */
58 InstalledMemoryMb
= 64;
59 memset(ControlRegion
, TEST_PATTERN1
, TEST_SIZE
);
60 memset(MembaseTop
, TEST_PATTERN1
, TEST_SIZE
);
63 if (memcmp(MembaseTop
, ControlRegion
, TEST_SIZE
) == 0)
65 /* Looks like there is memory .. maybe a 128MB box */
66 memset(ControlRegion
, TEST_PATTERN2
, TEST_SIZE
);
67 memset(MembaseTop
, TEST_PATTERN2
, TEST_SIZE
);
69 if (memcmp(MembaseTop
, ControlRegion
, TEST_SIZE
) == 0)
71 /* Definitely looks like there is memory */
72 if (memcmp(MembaseLow
, ControlRegion
, TEST_SIZE
) == 0)
74 /* Hell, we find the Test-string at 0x0 too! */
75 InstalledMemoryMb
= 64;
79 InstalledMemoryMb
= 128;
84 /* Set hardware for amount of memory detected */
85 WRITE_PORT_ULONG((ULONG
*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
86 WRITE_PORT_ULONG((ULONG
*) 0xcfc, InstalledMemoryMb
* 1024 * 1024 - 1);
88 /* 4 MB video framebuffer is reserved later using XboxMemReserveMemory() */
89 AvailableMemoryMb
= InstalledMemoryMb
;
92 FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap
[2];
94 PFREELDR_MEMORY_DESCRIPTOR
95 XboxMemGetMemoryMap(ULONG
*MemoryMapSize
)
97 TRACE("XboxMemGetMemoryMap()\n");
99 /* Synthesize memory map */
101 /* Available RAM block */
102 SetMemory(XboxMemoryMap
,
104 AvailableMemoryMb
* 1024 * 1024,
108 SetMemory(XboxMemoryMap
,
109 AvailableMemoryMb
* 1024 * 1024,
110 (InstalledMemoryMb
- AvailableMemoryMb
) * 1024 * 1024,
111 LoaderFirmwarePermanent
);
113 *MemoryMapSize
= PcMemFinalizeMemoryMap(XboxMemoryMap
);
114 return XboxMemoryMap
;
118 XboxMemReserveMemory(ULONG MbToReserve
)
120 /* This function is used to reserve video framebuffer in XboxVideoInit() */
122 if (InstalledMemoryMb
== 0)
124 /* Hmm, seems we're not initialized yet */
128 if (MbToReserve
> AvailableMemoryMb
)
130 /* Can't satisfy the request */
134 AvailableMemoryMb
-= MbToReserve
;
136 /* Top of available memory points to the space just reserved */
137 return (PVOID
)(AvailableMemoryMb
* 1024 * 1024);