+++ /dev/null
-/* $Id: xboxmem.c,v 1.3 2004/11/10 23:45:37 gvg Exp $
- *
- * FreeLoader
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Note: much of this code was based on knowledge and/or code developed
- * by the Xbox Linux group: http://www.xbox-linux.org
- */
-
-#include "freeldr.h"
-#include "debug.h"
-#include "mm.h"
-#include "rtl.h"
-#include "hardware.h"
-#include "machine.h"
-#include "machxbox.h"
-#include "portio.h"
-
-static U32 InstalledMemoryMb = 0;
-static U32 AvailableMemoryMb = 0;
-
-#define TEST_SIZE 0x200
-#define TEST_PATTERN1 0xaa
-#define TEST_PATTERN2 0x55
-
-VOID
-XboxMemInit(VOID)
-{
- U8 ControlRegion[TEST_SIZE];
- PVOID MembaseTop = (PVOID)(64 * 1024 * 1024);
- PVOID MembaseLow = (PVOID)0;
-
- (*(PU32)(0xfd000000 + 0x100200)) = 0x03070103 ;
- (*(PU32)(0xfd000000 + 0x100204)) = 0x11448000 ;
-
- WRITE_PORT_ULONG((U32*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
- WRITE_PORT_ULONG((U32*) 0xcfc, 0x7ffffff); /* Prep hardware for 128 Mb */
-
- InstalledMemoryMb = 64;
- memset(ControlRegion, TEST_PATTERN1, TEST_SIZE);
- memset(MembaseTop, TEST_PATTERN1, TEST_SIZE);
- __asm__ ("wbinvd\n");
-
- if (0 == memcmp(MembaseTop, ControlRegion, TEST_SIZE))
- {
- /* Looks like there is memory .. maybe a 128MB box */
- memset(ControlRegion, TEST_PATTERN2, TEST_SIZE);
- memset(MembaseTop, TEST_PATTERN2, TEST_SIZE);
- __asm__ ("wbinvd\n");
- if (0 == memcmp(MembaseTop, ControlRegion, TEST_SIZE))
- {
- /* Definitely looks like there is memory */
- if (0 == memcmp(MembaseLow, ControlRegion, TEST_SIZE))
- {
- /* Hell, we find the Test-string at 0x0 too ! */
- InstalledMemoryMb = 64;
- }
- else
- {
- InstalledMemoryMb = 128;
- }
- }
- }
-
- /* Set hardware for amount of memory detected */
- WRITE_PORT_ULONG((U32*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
- WRITE_PORT_ULONG((U32*) 0xcfc, InstalledMemoryMb * 1024 * 1024 - 1);
-
- AvailableMemoryMb = InstalledMemoryMb;
-}
-
-U32
-XboxMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, U32 MaxMemoryMapSize)
-{
- U32 EntryCount = 0;
-
- /* Synthesize memory map */
- if (1 <= MaxMemoryMapSize)
- {
- /* Available RAM block */
- BiosMemoryMap[0].BaseAddress = 0;
- BiosMemoryMap[0].Length = AvailableMemoryMb * 1024 * 1024;
- BiosMemoryMap[0].Type = MEMTYPE_USABLE;
- EntryCount = 1;
- }
-
- if (2 <= MaxMemoryMapSize)
- {
- /* Video memory */
- BiosMemoryMap[1].BaseAddress = AvailableMemoryMb * 1024 * 1024;
- BiosMemoryMap[1].Length = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024;
- BiosMemoryMap[1].Type = MEMTYPE_RESERVED;
- EntryCount = 2;
- }
-
- return EntryCount;
-}
-
-PVOID
-XboxMemReserveMemory(U32 MbToReserve)
-{
- if (0 == InstalledMemoryMb)
- {
- /* Hmm, seems we're not initialized yet */
- XboxMemInit();
- }
-
- if (AvailableMemoryMb < MbToReserve)
- {
- /* Can't satisfy the request */
- return NULL;
- }
-
- AvailableMemoryMb -= MbToReserve;
-
- /* Top of available memory points to the space just reserved */
- return (PVOID) (AvailableMemoryMb * 1024 * 1024);
-}
-
-/* EOF */