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;
29 extern PVOID FrameBuffer
;
30 extern ULONG FrameBufferSize
;
32 #define TEST_SIZE 0x200
33 #define TEST_PATTERN1 0xAA
34 #define TEST_PATTERN2 0x55
38 PFREELDR_MEMORY_DESCRIPTOR MemoryMap
,
39 ULONG_PTR BaseAddress
,
41 TYPE_OF_MEMORY MemoryType
);
45 PFREELDR_MEMORY_DESCRIPTOR MemoryMap
,
46 ULONG_PTR BaseAddress
,
48 TYPE_OF_MEMORY MemoryType
,
52 PcMemFinalizeMemoryMap(
53 PFREELDR_MEMORY_DESCRIPTOR MemoryMap
);
58 UCHAR ControlRegion
[TEST_SIZE
];
59 PVOID MembaseTop
= (PVOID
)(64 * 1024 * 1024);
60 PVOID MembaseLow
= (PVOID
)0;
62 (*(PULONG
)(0xfd000000 + 0x100200)) = 0x03070103;
63 (*(PULONG
)(0xfd000000 + 0x100204)) = 0x11448000;
65 WRITE_PORT_ULONG((ULONG
*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
66 WRITE_PORT_ULONG((ULONG
*) 0xcfc, 0x7ffffff); /* Prep hardware for 128 Mb */
68 InstalledMemoryMb
= 64;
69 memset(ControlRegion
, TEST_PATTERN1
, TEST_SIZE
);
70 memset(MembaseTop
, TEST_PATTERN1
, TEST_SIZE
);
73 if (memcmp(MembaseTop
, ControlRegion
, TEST_SIZE
) == 0)
75 /* Looks like there is memory .. maybe a 128MB box */
76 memset(ControlRegion
, TEST_PATTERN2
, TEST_SIZE
);
77 memset(MembaseTop
, TEST_PATTERN2
, TEST_SIZE
);
79 if (memcmp(MembaseTop
, ControlRegion
, TEST_SIZE
) == 0)
81 /* Definitely looks like there is memory */
82 if (memcmp(MembaseLow
, ControlRegion
, TEST_SIZE
) == 0)
84 /* Hell, we find the Test-string at 0x0 too! */
85 InstalledMemoryMb
= 64;
89 InstalledMemoryMb
= 128;
94 /* Set hardware for amount of memory detected */
95 WRITE_PORT_ULONG((ULONG
*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
96 WRITE_PORT_ULONG((ULONG
*) 0xcfc, InstalledMemoryMb
* 1024 * 1024 - 1);
98 AvailableMemoryMb
= InstalledMemoryMb
;
101 FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap
[MAX_BIOS_DESCRIPTORS
+ 1];
103 PFREELDR_MEMORY_DESCRIPTOR
104 XboxMemGetMemoryMap(ULONG
*MemoryMapSize
)
106 TRACE("XboxMemGetMemoryMap()\n");
107 /* FIXME: Obtain memory map via multiboot spec */
109 /* Synthesize memory map */
111 /* Available RAM block */
112 SetMemory(XboxMemoryMap
,
114 AvailableMemoryMb
* 1024 * 1024,
117 if (FrameBufferSize
!= 0)
120 ReserveMemory(XboxMemoryMap
,
121 (ULONG_PTR
)FrameBuffer
,
123 LoaderFirmwarePermanent
,
127 *MemoryMapSize
= PcMemFinalizeMemoryMap(XboxMemoryMap
);
128 return XboxMemoryMap
;