From 5dbb0fc055bddb0083ad9b5ede4265a4c4d1629f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 12 Mar 2010 14:08:26 +0100 Subject: [PATCH] Another round of macrofication --- include/grub/cs5536.h | 11 +++++++++-- include/grub/mips/yeeloong/boot.h | 2 ++ include/grub/mips/yeeloong/pci.h | 8 ++++---- kern/mips/yeeloong/fwstart.S | 22 ++++++++++++---------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/include/grub/cs5536.h b/include/grub/cs5536.h index 3f06bdb68..ec554f002 100644 --- a/include/grub/cs5536.h +++ b/include/grub/cs5536.h @@ -46,8 +46,15 @@ #define GRUB_CS5536_SMB_REG_CTRL2_ENABLE 0x1 #define GRUB_CS5536_SMB_REG_CTRL3 0x6 -#define GRUB_CS5536_LBAR_ADDR_MASK 0x000000000000fff8ULL -#define GRUB_CS5536_LBAR_ENABLE 0x0000000100000000ULL +#ifdef ASM_FILE +#define GRUB_ULL(x) x +#else +#define GRUB_ULL(x) x ## ULL +#endif + +#define GRUB_CS5536_LBAR_ADDR_MASK GRUB_ULL (0x000000000000fff8) +#define GRUB_CS5536_LBAR_ENABLE GRUB_ULL (0x0000000100000000) +#define GRUB_CS5536_LBAR_MASK_MASK GRUB_ULL (0x0000f00000000000) /* PMON-compatible LBARs. */ #define GRUB_CS5536_LBAR_GPIO 0x0b000 diff --git a/include/grub/mips/yeeloong/boot.h b/include/grub/mips/yeeloong/boot.h index 6a4189ede..eda9c6ad5 100644 --- a/include/grub/mips/yeeloong/boot.h +++ b/include/grub/mips/yeeloong/boot.h @@ -26,5 +26,7 @@ #define GRUB_MACHINE_DDR2_BASE 0xaffffe00 #define GRUB_MACHINE_DDR2_REG1_HI_8BANKS 0x00000001 +#define GRUB_MACHINE_DDR2_REG_SIZE 0x8 +#define GRUB_MACHINE_DDR2_REG_STEP 0x10 #endif diff --git a/include/grub/mips/yeeloong/pci.h b/include/grub/mips/yeeloong/pci.h index f50cdcb35..aa5e0bbea 100644 --- a/include/grub/mips/yeeloong/pci.h +++ b/include/grub/mips/yeeloong/pci.h @@ -30,12 +30,12 @@ #define GRUB_MACHINE_PCI_IO_BASE 0xbfd00000 #define GRUB_MACHINE_PCI_CONFSPACE 0xbfe80000 +#define GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR 0xbfe00118 + #ifndef ASM_FILE -#define GRUB_MACHINE_PCI_CONF_CTRL_REG (*(volatile grub_uint32_t *) 0xbfe00118) +#define GRUB_MACHINE_PCI_CONF_CTRL_REG (*(volatile grub_uint32_t *) \ + GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR) #define GRUB_MACHINE_PCI_IO_CTRL_REG (*(volatile grub_uint32_t *) 0xbfe00110) -#else -#define GRUB_MACHINE_PCI_CONF_CTRL_REG_HI 0xbfe0 -#define GRUB_MACHINE_PCI_CONF_CTRL_REG_LO 0x0118 #endif #define GRUB_MACHINE_PCI_WIN_MASK_SIZE 6 #define GRUB_MACHINE_PCI_WIN_MASK ((1 << GRUB_MACHINE_PCI_WIN_MASK_SIZE) - 1) diff --git a/kern/mips/yeeloong/fwstart.S b/kern/mips/yeeloong/fwstart.S index c7ed420a4..4a9a749f7 100644 --- a/kern/mips/yeeloong/fwstart.S +++ b/kern/mips/yeeloong/fwstart.S @@ -40,7 +40,7 @@ __start: /* Resulting value is kept in GRUB_MACHINE_PCI_CONF_CTRL_REG. This way we don't need to sacrifice a register for it. */ /* We have only one bus (0). Function is 0. */ - lui $t0, GRUB_MACHINE_PCI_CONF_CTRL_REG_HI + lui $t0, %hi(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR) lui $t1, %hi(GRUB_MACHINE_PCI_CONFSPACE) lui $t3, %hi(GRUB_CS5536_PCIID) addiu $t3, $t3, %lo(GRUB_CS5536_PCIID) @@ -50,7 +50,7 @@ __start: andi $t4, $t4, ((1 << GRUB_PCI_NUM_DEVICES) - 1) beql $t4, $zero, fatal addiu $a0, $a0, %lo(no_cs5536) - sw $t4, GRUB_MACHINE_PCI_CONF_CTRL_REG_LO($t0) + sw $t4, %lo(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR) ($t0) lw $t2, (%lo(GRUB_MACHINE_PCI_CONFSPACE) + GRUB_PCI_REG_PCI_ID) ($t1) bnel $t2, $t3, 1b sll $t4, $t4, 1 @@ -67,7 +67,8 @@ __start: ori $a1, $zero, GRUB_CS5536_LBAR_GPIO /* Set mask to 0xf and enabled bit to 1. */ bal wrmsr - ori $a2, $zero, 0xf001 + ori $a2, $zero, ((GRUB_CS5536_LBAR_MASK_MASK \ + | GRUB_CS5536_LBAR_ENABLE) >> 32) /* Set SMBUS LBAR. */ lui $a0, %hi(GRUB_CS5536_MSR_SMB_BAR) @@ -75,7 +76,8 @@ __start: ori $a1, $zero, GRUB_CS5536_LBAR_SMBUS /* Set mask to 0xf and enabled bit to 1. */ bal wrmsr - ori $a2, $zero, 0xf001 + ori $a2, $zero, ((GRUB_CS5536_LBAR_MASK_MASK \ + | GRUB_CS5536_LBAR_ENABLE) >> 32) lui $a0, %hi(smbus_enabled) bal message @@ -430,7 +432,7 @@ write_dumpreg: sd $t2, 0($t4) addiu $t4, $t4, 0x10 jr $ra - addiu $t6, $t6, 0x8 + addiu $t6, $t6, GRUB_MACHINE_DDR2_REG_SIZE continue: lui $t4, %hi(GRUB_MACHINE_DDR2_BASE) @@ -442,7 +444,7 @@ continue: addiu $t6, $t6, %lo(regdump) /* 1 */ - ori $a1, $a1, 0x50 + ori $a1, $a1, GRUB_SMB_RAM_START_ADDR move $t8, $zero lui $t5, 0x0001 bal read_spd @@ -455,7 +457,7 @@ continue: dsll $t8, $t8, 32 or $t5, $t5, $t8 sd $t5, 0 ($t4) - addiu $t4, $t4, 0x10 + addiu $t4, $t4, GRUB_MACHINE_DDR2_REG_STEP /* 2 */ bal write_dumpreg @@ -509,17 +511,17 @@ continue: or $t5, $t5, $v0 sd $t5, 0 ($t4) - addiu $t4, $t4, 0x10 + addiu $t4, $t4, GRUB_MACHINE_DDR2_REG_STEP ori $t7, $zero, 0x16 1: ld $t2, 0($t6) sd $t2, 0($t4) - addiu $t4, $t4, 0x10 + addiu $t4, $t4, GRUB_MACHINE_DDR2_REG_STEP addiu $t7, $t7, -1 bne $t7, $zero, 1b - addiu $t6, $t6, 0x8 + addiu $t6, $t6, GRUB_MACHINE_DDR2_REG_SIZE lui $t4, %hi(GRUB_MACHINE_DDR2_BASE) ld $t5, (%lo(GRUB_MACHINE_DDR2_BASE) + 0x30) ($t4)