https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f1410d2b094f6452d0962…
commit f1410d2b094f6452d0962ef5060b9f65fe1def6c
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Mon May 24 18:02:16 2021 +0300
Commit: Stanislav Motylkov <x86corez(a)gmail.com>
CommitDate: Mon May 24 18:02:16 2021 +0300
[FREELDR] Replace CONFIG_CMD macro with a straightforward bitfield struct
Also fix magic values related to PCI registers.
---
boot/freeldr/freeldr/arch/i386/xbox/machxbox.c | 15 +++++++++++--
boot/freeldr/freeldr/arch/i386/xbox/xboxmem.c | 19 +++++++++++-----
boot/freeldr/freeldr/include/arch/pc/hardware.h | 26 +++++++++++++++++++---
.../freeldr/include/arch/powerpc/hardware.h | 3 ---
4 files changed, 50 insertions(+), 13 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c
b/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c
index 1551c664c29..781c2e946fc 100644
--- a/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c
+++ b/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c
@@ -301,14 +301,25 @@ VOID XboxHwIdle(VOID)
VOID
MachInit(const char *CmdLine)
{
+ PCI_TYPE1_CFG_BITS PciCfg1;
ULONG PciId;
memset(&MachVtbl, 0, sizeof(MACHVTBL));
/* Check for Xbox by identifying device at PCI 0:0:0, if it's
* 0x10DE/0x02A5 then we're running on an Xbox */
- WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(0, 0, 0));
- PciId = READ_PORT_ULONG((PULONG)0xCFC);
+
+ /* Select Host to PCI bridge */
+ PciCfg1.u.bits.Enable = 1;
+ PciCfg1.u.bits.BusNumber = 0;
+ PciCfg1.u.bits.DeviceNumber = 0;
+ PciCfg1.u.bits.FunctionNumber = 0;
+ /* Select register VendorID & DeviceID */
+ PciCfg1.u.bits.RegisterNumber = 0x00;
+ PciCfg1.u.bits.Reserved = 0;
+
+ WRITE_PORT_ULONG(PCI_TYPE1_ADDRESS_PORT, PciCfg1.u.AsULONG);
+ PciId = READ_PORT_ULONG((PULONG)PCI_TYPE1_DATA_PORT);
if (PciId != 0x02A510DE)
{
ERR("This is not original Xbox!\n");
diff --git a/boot/freeldr/freeldr/arch/i386/xbox/xboxmem.c
b/boot/freeldr/freeldr/arch/i386/xbox/xboxmem.c
index 1990199d70b..2f59f04278b 100644
--- a/boot/freeldr/freeldr/arch/i386/xbox/xboxmem.c
+++ b/boot/freeldr/freeldr/arch/i386/xbox/xboxmem.c
@@ -57,6 +57,7 @@ PcMemFinalizeMemoryMap(
VOID
XboxMemInit(VOID)
{
+ PCI_TYPE1_CFG_BITS PciCfg1;
UCHAR ControlRegion[TEST_SIZE];
PVOID MembaseTop = (PVOID)(64 * 1024 * 1024);
PVOID MembaseLow = (PVOID)0;
@@ -64,9 +65,17 @@ XboxMemInit(VOID)
WRITE_REGISTER_ULONG((PULONG)(NvBase + NV2A_FB_CFG0), 0x03070103);
WRITE_REGISTER_ULONG((PULONG)(NvBase + NV2A_FB_CFG0 + 4), 0x11448000);
- /* Prep hardware for 128 Mb */
- WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(0, 0, 0x84));
- WRITE_PORT_ULONG((PULONG)0xCFC, 0x7FFFFFF);
+ /* Select Host to PCI bridge */
+ PciCfg1.u.bits.Enable = 1;
+ PciCfg1.u.bits.BusNumber = 0;
+ PciCfg1.u.bits.DeviceNumber = 0;
+ PciCfg1.u.bits.FunctionNumber = 0;
+ PciCfg1.u.bits.Reserved = 0;
+ /* Prepare hardware for 128 MB */
+ PciCfg1.u.bits.RegisterNumber = 0x84;
+
+ WRITE_PORT_ULONG(PCI_TYPE1_ADDRESS_PORT, PciCfg1.u.AsULONG);
+ WRITE_PORT_ULONG((PULONG)PCI_TYPE1_DATA_PORT, 0x7FFFFFF);
InstalledMemoryMb = 64;
memset(ControlRegion, TEST_PATTERN1, TEST_SIZE);
@@ -95,8 +104,8 @@ XboxMemInit(VOID)
}
/* Set hardware for amount of memory detected */
- WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(0, 0, 0x84));
- WRITE_PORT_ULONG((PULONG)0xCFC, InstalledMemoryMb * 1024 * 1024 - 1);
+ WRITE_PORT_ULONG(PCI_TYPE1_ADDRESS_PORT, PciCfg1.u.AsULONG);
+ WRITE_PORT_ULONG((PULONG)PCI_TYPE1_DATA_PORT, InstalledMemoryMb * 1024 * 1024 - 1);
AvailableMemoryMb = InstalledMemoryMb;
}
diff --git a/boot/freeldr/freeldr/include/arch/pc/hardware.h
b/boot/freeldr/freeldr/include/arch/pc/hardware.h
index 56e6028ed06..fb547212ea8 100644
--- a/boot/freeldr/freeldr/include/arch/pc/hardware.h
+++ b/boot/freeldr/freeldr/include/arch/pc/hardware.h
@@ -20,9 +20,6 @@
#pragma once
-#define CONFIG_CMD(bus, dev_fn, where) \
- (0x80000000 | (((ULONG)(bus)) << 16) | (((dev_fn) & 0x1F) << 11) |
(((dev_fn) & 0xE0) << 3) | ((where) & ~3))
-
#define TAG_HW_RESOURCE_LIST 'lRwH'
#define TAG_HW_DISK_CONTEXT 'cDwH'
@@ -32,6 +29,29 @@
VOID StallExecutionProcessor(ULONG Microseconds);
VOID HalpCalibrateStallExecution(VOID);
+/* PCI Type 1 Ports */
+#define PCI_TYPE1_ADDRESS_PORT (PULONG)0xCF8
+#define PCI_TYPE1_DATA_PORT 0xCFC
+
+/* PCI Type 1 Configuration Register */
+typedef struct _PCI_TYPE1_CFG_BITS
+{
+ union
+ {
+ struct
+ {
+ ULONG RegisterNumber:8;
+ ULONG FunctionNumber:3;
+ ULONG DeviceNumber:5;
+ ULONG BusNumber:8;
+ ULONG Reserved:7;
+ ULONG Enable:1;
+ } bits;
+
+ ULONG AsULONG;
+ } u;
+} PCI_TYPE1_CFG_BITS, *PPCI_TYPE1_CFG_BITS;
+
typedef
PCM_PARTIAL_RESOURCE_LIST
(*GET_HARDDISK_CONFIG_DATA)(UCHAR DriveNumber, ULONG* pSize);
diff --git a/boot/freeldr/freeldr/include/arch/powerpc/hardware.h
b/boot/freeldr/freeldr/include/arch/powerpc/hardware.h
index faefe779684..fcf663ad50a 100644
--- a/boot/freeldr/freeldr/include/arch/powerpc/hardware.h
+++ b/boot/freeldr/freeldr/include/arch/powerpc/hardware.h
@@ -24,9 +24,6 @@
#include "../../reactos/registry.h"
#endif
-#define CONFIG_CMD(bus, dev_fn, where) \
- (0x80000000 | (((ULONG)(bus)) << 16) | (((dev_fn) & 0x1F) << 11) |
(((dev_fn) & 0xE0) << 3) | ((where) & ~3))
-
/* PROTOTYPES ***************************************************************/
/* hardware.c */