ReactOS 0.4.15-dev-7924-g5949c20
xboxmem.c
Go to the documentation of this file.
1/*
2 * FreeLoader
3 *
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.
8 *
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.
13 *
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.
17 *
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
20 */
21
22#include <freeldr.h>
23#include <debug.h>
24
26
30extern ULONG NvBase;
31extern PVOID FrameBuffer;
33
34#define TEST_SIZE 0x200
35#define TEST_PATTERN1 0xAA
36#define TEST_PATTERN2 0x55
37
38extern VOID
43 TYPE_OF_MEMORY MemoryType);
44
45extern VOID
50 TYPE_OF_MEMORY MemoryType,
51 PCHAR Usage);
52
53extern ULONG
56
57static
58VOID
60{
61 PCI_TYPE1_CFG_BITS PciCfg1;
62 ULONG PciData;
63
64 /* Select PCI to PCI bridge */
65 PciCfg1.u.bits.Enable = 1;
66 PciCfg1.u.bits.BusNumber = 0;
67 PciCfg1.u.bits.DeviceNumber = 8;
68 PciCfg1.u.bits.FunctionNumber = 0;
69 /* Select register VendorID & DeviceID */
70 PciCfg1.u.bits.RegisterNumber = 0x00;
71 PciCfg1.u.bits.Reserved = 0;
72
75
76 if (PciData == 0x01B810DE)
77 {
78 /* Select register PrimaryBus/SecondaryBus/SubordinateBus/SecondaryLatency */
79 PciCfg1.u.bits.RegisterNumber = 0x18;
81
82 /* Link uninitialized PCI bridge to the empty PCI bus 2,
83 * it's not supposed to have any devices attached anyway */
85 PciData &= 0xFF0000FF;
86 PciData |= 0x00020200;
88 }
89
90 /* Select AGP to PCI bridge */
91 PciCfg1.u.bits.DeviceNumber = 30;
92 /* Select register VendorID & DeviceID */
93 PciCfg1.u.bits.RegisterNumber = 0x00;
94
97
98 if (PciData == 0x01B710DE)
99 {
100 /* Zero out uninitialized AGP Host bridge BARs */
101
102 /* Select register BAR0 */
103 PciCfg1.u.bits.RegisterNumber = 0x10;
105 /* Zero it out */
107
108 /* Select register BAR1 */
109 PciCfg1.u.bits.RegisterNumber = 0x14;
111 /* Zero it out */
113 }
114}
115
116VOID
118{
119 PCI_TYPE1_CFG_BITS PciCfg1;
120 UCHAR ControlRegion[TEST_SIZE];
121 PVOID MembaseTop = (PVOID)(64 * 1024 * 1024);
122 PVOID MembaseLow = (PVOID)0;
123
125 WRITE_REGISTER_ULONG((PULONG)(NvBase + NV2A_FB_CFG0 + 4), 0x11448000);
126
127 /* Select Host to PCI bridge */
128 PciCfg1.u.bits.Enable = 1;
129 PciCfg1.u.bits.BusNumber = 0;
130 PciCfg1.u.bits.DeviceNumber = 0;
131 PciCfg1.u.bits.FunctionNumber = 0;
132 PciCfg1.u.bits.Reserved = 0;
133 /* Prepare hardware for 128 MB */
134 PciCfg1.u.bits.RegisterNumber = 0x84;
135
138
140 memset(ControlRegion, TEST_PATTERN1, TEST_SIZE);
141 memset(MembaseTop, TEST_PATTERN1, TEST_SIZE);
142 __wbinvd();
143
144 if (memcmp(MembaseTop, ControlRegion, TEST_SIZE) == 0)
145 {
146 /* Looks like there is memory .. maybe a 128MB box */
147 memset(ControlRegion, TEST_PATTERN2, TEST_SIZE);
148 memset(MembaseTop, TEST_PATTERN2, TEST_SIZE);
149 __wbinvd();
150 if (memcmp(MembaseTop, ControlRegion, TEST_SIZE) == 0)
151 {
152 /* Definitely looks like there is memory */
153 if (memcmp(MembaseLow, ControlRegion, TEST_SIZE) == 0)
154 {
155 /* Hell, we find the Test-string at 0x0 too! */
157 }
158 else
159 {
160 InstalledMemoryMb = 128;
161 }
162 }
163 }
164
165 /* Set hardware for amount of memory detected */
168
170
172}
173
176{
178
179 if (!MultibootInfoPtr)
180 {
181 ERR("Multiboot info structure not found!\n");
182 return NULL;
183 }
184
186 {
187 ERR("Multiboot memory map is not passed!\n");
188 return NULL;
189 }
190
192
193 if (!MemoryMap ||
196 {
197 ERR("Multiboot memory map structure is malformed!\n");
198 return NULL;
199 }
200
202 return MemoryMap;
203}
204
207{
208 switch (Type)
209 {
210 case 0: // Video RAM
212 case 1: // Available RAM
213 return LoaderFree;
214 case 3: // ACPI area
216 case 4: // Hibernation area
217 return LoaderSpecialMemory;
218 case 5: // Reserved or invalid memory
219 return LoaderSpecialMemory;
220 default:
222 }
223}
224
226
229{
230 memory_map_t * MbMap;
231 INT Count, i;
232
233 TRACE("XboxMemGetMemoryMap()\n");
234
236 if (MbMap)
237 {
238 /* Obtain memory map via multiboot spec */
239
240 for (i = 0; i < Count; i++, MbMap++)
241 {
242 TRACE("i = %d, base_addr_low = 0x%p, length_low = 0x%p\n", i, MbMap->base_addr_low, MbMap->length_low);
243
244 if (MbMap->base_addr_high > 0 || MbMap->length_high > 0)
245 {
246 ERR("Memory descriptor base or size is greater than 4 GB, should not happen on Xbox!\n");
247 ASSERT(FALSE);
248 }
249
251 MbMap->base_addr_low,
252 MbMap->length_low,
254 }
255 }
256 else
257 {
258 /* Synthesize memory map */
259
260 /* Available RAM block */
262 0,
263 AvailableMemoryMb * 1024 * 1024,
264 LoaderFree);
265
266 if (FrameBufferSize != 0)
267 {
268 /* Video memory */
273 "Video memory");
274 }
275 }
276
277 *MemoryMapSize = PcMemFinalizeMemoryMap(XboxMemoryMap);
278 return XboxMemoryMap;
279}
280
281/* EOF */
Type
Definition: Type.h:7
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define WRITE_REGISTER_ULONG(r, v)
Definition: arm.h:27
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
#define PCI_TYPE1_DATA_PORT
Definition: hardware.h:34
#define PCI_TYPE1_ADDRESS_PORT
Definition: hardware.h:33
#define ERR(fmt,...)
Definition: debug.h:110
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:103
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define MB_INFO_FLAG_MEMORY_MAP
Definition: multiboot.h:50
struct memory_map memory_map_t
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
int Count
Definition: noreturn.cpp:7
#define MAX_BIOS_DESCRIPTORS
Definition: pcbios.h:12
@ LoaderFree
Definition: arc.h:176
@ LoaderFirmwareTemporary
Definition: arc.h:179
@ LoaderFirmwarePermanent
Definition: arc.h:180
@ LoaderSpecialMemory
Definition: arc.h:196
enum _TYPE_OF_MEMORY TYPE_OF_MEMORY
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
union _PCI_TYPE1_CFG_BITS::@163 u
struct _PCI_TYPE1_CFG_BITS::@163::@164 bits
unsigned long base_addr_low
Definition: multiboot.h:119
unsigned long length_low
Definition: multiboot.h:121
unsigned long type
Definition: multiboot.h:123
unsigned long base_addr_high
Definition: multiboot.h:120
unsigned long length_high
Definition: multiboot.h:122
unsigned long mmap_addr
Definition: multiboot.h:109
unsigned long mmap_length
Definition: multiboot.h:108
unsigned long flags
Definition: multiboot.h:96
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
memory_map_t * XboxGetMultibootMemoryMap(INT *Count)
Definition: xboxmem.c:175
static VOID XboxInitializePCI(VOID)
Definition: xboxmem.c:59
ULONG FrameBufferSize
Definition: xboxvideo.c:29
FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap[MAX_BIOS_DESCRIPTORS+1]
Definition: xboxmem.c:225
multiboot_info_t * MultibootInfoPtr
ULONG PcMemFinalizeMemoryMap(PFREELDR_MEMORY_DESCRIPTOR MemoryMap)
Definition: pcmem.c:547
PVOID FrameBuffer
Definition: xboxvideo.c:28
#define TEST_PATTERN2
Definition: xboxmem.c:36
#define TEST_SIZE
Definition: xboxmem.c:34
ULONG NvBase
Definition: xboxvideo.c:27
static ULONG AvailableMemoryMb
Definition: xboxmem.c:28
VOID ReserveMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType, PCHAR Usage)
Definition: pcmem.c:484
PFREELDR_MEMORY_DESCRIPTOR XboxMemGetMemoryMap(ULONG *MemoryMapSize)
Definition: xboxmem.c:228
#define TEST_PATTERN1
Definition: xboxmem.c:35
VOID XboxMemInit(VOID)
Definition: xboxmem.c:117
TYPE_OF_MEMORY XboxMultibootMemoryType(ULONG Type)
Definition: xboxmem.c:206
static ULONG InstalledMemoryMb
Definition: xboxmem.c:27
VOID SetMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType)
Definition: pcmem.c:527
#define NV2A_FB_CFG0
Definition: xgpu.h:19
unsigned char UCHAR
Definition: xmlstorage.h:181