5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Note: much of this code was based on knowledge and/or code developed
20 * by the Xbox Linux group: http://www.xbox-linux.org
32 static U32 InstalledMemoryMb
= 0;
33 static U32 AvailableMemoryMb
= 0;
35 #define TEST_SIZE 0x200
36 #define TEST_PATTERN1 0xaa
37 #define TEST_PATTERN2 0x55
42 U8 ControlRegion
[TEST_SIZE
];
43 PVOID MembaseTop
= (PVOID
)(64 * 1024 * 1024);
44 PVOID MembaseLow
= (PVOID
)0;
46 (*(PU32
)(0xfd000000 + 0x100200)) = 0x03070103 ;
47 (*(PU32
)(0xfd000000 + 0x100204)) = 0x11448000 ;
49 WRITE_PORT_ULONG((U32
*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
50 WRITE_PORT_ULONG((U32
*) 0xcfc, 0x7ffffff); /* Prep hardware for 128 Mb */
52 InstalledMemoryMb
= 64;
53 memset(ControlRegion
, TEST_PATTERN1
, TEST_SIZE
);
54 memset(MembaseTop
, TEST_PATTERN1
, TEST_SIZE
);
57 if (0 == memcmp(MembaseTop
, ControlRegion
, TEST_SIZE
))
59 /* Looks like there is memory .. maybe a 128MB box */
60 memset(ControlRegion
, TEST_PATTERN2
, TEST_SIZE
);
61 memset(MembaseTop
, TEST_PATTERN2
, TEST_SIZE
);
63 if (0 == memcmp(MembaseTop
, ControlRegion
, TEST_SIZE
))
65 /* Definitely looks like there is memory */
66 if (0 == memcmp(MembaseLow
, ControlRegion
, TEST_SIZE
))
68 /* Hell, we find the Test-string at 0x0 too ! */
69 InstalledMemoryMb
= 64;
73 InstalledMemoryMb
= 128;
78 /* Set hardware for amount of memory detected */
79 WRITE_PORT_ULONG((U32
*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
80 WRITE_PORT_ULONG((U32
*) 0xcfc, InstalledMemoryMb
* 1024 * 1024 - 1);
82 AvailableMemoryMb
= InstalledMemoryMb
;
86 XboxMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap
, U32 MaxMemoryMapSize
)
90 /* Synthesize memory map */
91 if (1 <= MaxMemoryMapSize
)
93 /* Available RAM block */
94 BiosMemoryMap
[0].BaseAddress
= 0;
95 BiosMemoryMap
[0].Length
= AvailableMemoryMb
* 1024 * 1024;
96 BiosMemoryMap
[0].Type
= MEMTYPE_USABLE
;
100 if (2 <= MaxMemoryMapSize
)
103 BiosMemoryMap
[1].BaseAddress
= AvailableMemoryMb
* 1024 * 1024;
104 BiosMemoryMap
[1].Length
= (InstalledMemoryMb
- AvailableMemoryMb
) * 1024 * 1024;
105 BiosMemoryMap
[1].Type
= MEMTYPE_RESERVED
;
113 XboxMemReserveMemory(U32 MbToReserve
)
115 if (0 == InstalledMemoryMb
)
117 /* Hmm, seems we're not initialized yet */
121 if (AvailableMemoryMb
< MbToReserve
)
123 /* Can't satisfy the request */
127 AvailableMemoryMb
-= MbToReserve
;
129 /* Top of available memory points to the space just reserved */
130 return (PVOID
) (AvailableMemoryMb
* 1024 * 1024);