[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnewsense-dev] [loongson-PATCH-v1 07/27] replace tons of magic numbers
From: |
wuzhangjin |
Subject: |
[Gnewsense-dev] [loongson-PATCH-v1 07/27] replace tons of magic numbers by understandable symbols |
Date: |
Thu, 21 May 2009 05:51:40 +0800 |
From: Wu Zhangjin <address@hidden>
tons of magic numbers are replaced by understandable symbols, and two
new header files are added to support this substitution.
Signed-off-by: Wu Zhangjin <address@hidden>
---
arch/mips/include/asm/mach-loongson/loongson.h | 3 ++
arch/mips/include/asm/mach-loongson/machine.h | 27 ++++++++++++++++++
arch/mips/include/asm/mach-loongson/mem.h | 8 +++++
arch/mips/loongson/fuloong-2e/bonito-irq.c | 3 +-
arch/mips/loongson/fuloong-2e/dbg_io.c | 12 +++----
arch/mips/loongson/fuloong-2e/irq.c | 7 ++--
arch/mips/loongson/fuloong-2e/mem.c | 9 +++--
arch/mips/loongson/fuloong-2e/misc.c | 4 ++-
arch/mips/loongson/fuloong-2e/pci.c | 36 ++++++++++++++++--------
arch/mips/loongson/fuloong-2e/reset.c | 19 +++++++-----
arch/mips/loongson/fuloong-2e/setup.c | 5 ++-
11 files changed, 96 insertions(+), 37 deletions(-)
create mode 100644 arch/mips/include/asm/mach-loongson/machine.h
create mode 100644 arch/mips/include/asm/mach-loongson/mem.h
diff --git a/arch/mips/include/asm/mach-loongson/loongson.h
b/arch/mips/include/asm/mach-loongson/loongson.h
index bce85a8..5ad629e 100644
--- a/arch/mips/include/asm/mach-loongson/loongson.h
+++ b/arch/mips/include/asm/mach-loongson/loongson.h
@@ -14,6 +14,9 @@
#ifndef __LOONGSON_H
#define __LOONGSON_H
+#include <linux/io.h>
+#include <linux/init.h>
+
/* loongson internal northbridge initialization */
extern void bonito_irq_init(void);
diff --git a/arch/mips/include/asm/mach-loongson/machine.h
b/arch/mips/include/asm/mach-loongson/machine.h
new file mode 100644
index 0000000..5f2cd3a
--- /dev/null
+++ b/arch/mips/include/asm/mach-loongson/machine.h
@@ -0,0 +1,27 @@
+/*
+ * board-specific header file
+ *
+ * Copyright (c) 2009 Wu Zhangjin <address@hidden>
+ *
+ * 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.
+ */
+
+#ifndef __MACHINE_H
+#define __MACHINE_H
+
+#define MACH_NAME "lemote-fuloong(2e)"
+
+#define LOONGSON_UART_BASE 0x1fd003f8
+
+#define LOONGSON_NORTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 2)
+#define LOONGSON_UART_IRQ (MIPS_CPU_IRQ_BASE + 4)
+#define LOONGSON_SOUTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 5)
+#define LOONGSON_TIMER_IRQ (MIPS_CPU_IRQ_BASE + 7)
+#define LOONGSON_DMATIMEOUT_IRQ (LOONGSON_IRQ_BASE + 10)
+
+
+#endif /* ! __MACHINE_H */
diff --git a/arch/mips/include/asm/mach-loongson/mem.h
b/arch/mips/include/asm/mach-loongson/mem.h
new file mode 100644
index 0000000..ad01dc2
--- /dev/null
+++ b/arch/mips/include/asm/mach-loongson/mem.h
@@ -0,0 +1,8 @@
+#ifndef __MEM_H
+#define __MEM_H
+
+#define LOONGSON_HIGHMEM_START 0x20000000
+#define LOONGSON_MMIO_MEM_START 0x10000000
+#define LOONGSON_MMIO_MEM_END 0x20000000
+
+#endif /* !__MEM_H */
diff --git a/arch/mips/loongson/fuloong-2e/bonito-irq.c
b/arch/mips/loongson/fuloong-2e/bonito-irq.c
index 8a32651..1f43447 100644
--- a/arch/mips/loongson/fuloong-2e/bonito-irq.c
+++ b/arch/mips/loongson/fuloong-2e/bonito-irq.c
@@ -31,6 +31,7 @@
#include <linux/interrupt.h>
#include <loongson.h>
+#include <machine.h>
static inline void bonito_irq_enable(unsigned int irq)
{
@@ -64,5 +65,5 @@ void bonito_irq_init(void)
for (i = LOONGSON_IRQ_BASE; i < LOONGSON_IRQ_BASE + 32; i++)
set_irq_chip_and_handler(i, &bonito_irq_type, handle_level_irq);
- setup_irq(LOONGSON_IRQ_BASE + 10, &dma_timeout_irqaction);
+ setup_irq(LOONGSON_DMATIMEOUT_IRQ, &dma_timeout_irqaction);
}
diff --git a/arch/mips/loongson/fuloong-2e/dbg_io.c
b/arch/mips/loongson/fuloong-2e/dbg_io.c
index 84f8320..1ace08f 100644
--- a/arch/mips/loongson/fuloong-2e/dbg_io.c
+++ b/arch/mips/loongson/fuloong-2e/dbg_io.c
@@ -28,12 +28,13 @@
*
*/
-#include <linux/io.h>
-#include <linux/init.h>
#include <linux/types.h>
#include <asm/serial.h>
+#include <loongson.h>
+#include <machine.h>
+
#define UART16550_BAUD_2400 2400
#define UART16550_BAUD_4800 4800
#define UART16550_BAUD_9600 9600
@@ -59,11 +60,8 @@
/* ----------------------------------------------------- */
/* === CONFIG === */
-#ifdef CONFIG_64BIT
-#define BASE (0xffffffffbfd003f8)
-#else
-#define BASE (0xbfd003f8)
-#endif
+
+#define BASE
ioremap_nocache(LOONGSON_UART_BASE, 8)
#define MAX_BAUD BASE_BAUD
/* === END OF CONFIG === */
diff --git a/arch/mips/loongson/fuloong-2e/irq.c
b/arch/mips/loongson/fuloong-2e/irq.c
index edd1563..e04ff30 100644
--- a/arch/mips/loongson/fuloong-2e/irq.c
+++ b/arch/mips/loongson/fuloong-2e/irq.c
@@ -31,6 +31,7 @@
#include <asm/i8259.h>
#include <loongson.h>
+#include <machine.h>
/*
* the first level int-handler will jump here if it is a bonito irq
@@ -75,7 +76,7 @@ asmlinkage void plat_irq_dispatch(void)
unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
if (pending & CAUSEF_IP7)
- do_IRQ(MIPS_CPU_IRQ_BASE + 7);
+ do_IRQ(LOONGSON_TIMER_IRQ);
else if (pending & CAUSEF_IP5)
i8259_irqdispatch();
else if (pending & CAUSEF_IP2)
@@ -129,8 +130,8 @@ void __init arch_init_irq(void)
*/
/* bonito irq at IP2 */
- setup_irq(MIPS_CPU_IRQ_BASE + 2, &cascade_irqaction);
+ setup_irq(LOONGSON_NORTH_BRIDGE_IRQ, &cascade_irqaction);
/* 8259 irq at IP5 */
- setup_irq(MIPS_CPU_IRQ_BASE + 5, &cascade_irqaction);
+ setup_irq(LOONGSON_SOUTH_BRIDGE_IRQ, &cascade_irqaction);
}
diff --git a/arch/mips/loongson/fuloong-2e/mem.c
b/arch/mips/loongson/fuloong-2e/mem.c
index 2a0f4e6..7f6ee37 100644
--- a/arch/mips/loongson/fuloong-2e/mem.c
+++ b/arch/mips/loongson/fuloong-2e/mem.c
@@ -7,18 +7,18 @@
#include <linux/fs.h>
#include <linux/mm.h>
-#include <linux/init.h>
#include <asm/bootinfo.h>
#include <loongson.h>
+#include <mem.h>
void __init prom_init_memory(void)
{
add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
#ifdef CONFIG_64BIT
if (highmemsize > 0) {
- add_memory_region(0x20000000,
+ add_memory_region(LOONGSON_HIGHMEM_START,
highmemsize << 20, BOOT_MEM_RAM);
}
#endif /* CONFIG_64BIT */
@@ -34,6 +34,7 @@ int __uncached_access(struct file *file, unsigned long addr)
* On the Lemote Loongson 2e system, the peripheral registers
* reside between 0x1000:0000 and 0x2000:0000.
*/
- return addr >= __pa(high_memory) ||
- ((addr >= 0x10000000) && (addr < 0x20000000));
+ return addr >= __pa(high_memory) || \
+ ((addr >= LOONGSON_MMIO_MEM_START) && \
+ (addr < LOONGSON_MMIO_MEM_END));
}
diff --git a/arch/mips/loongson/fuloong-2e/misc.c
b/arch/mips/loongson/fuloong-2e/misc.c
index d9532ca..1b8044c 100644
--- a/arch/mips/loongson/fuloong-2e/misc.c
+++ b/arch/mips/loongson/fuloong-2e/misc.c
@@ -7,7 +7,9 @@
* option) any later version.
*/
+#include <machine.h>
+
const char *get_system_type(void)
{
- return "fuloong-2e";
+ return MACH_NAME;
}
diff --git a/arch/mips/loongson/fuloong-2e/pci.c
b/arch/mips/loongson/fuloong-2e/pci.c
index cfc09a1..89bc1af 100644
--- a/arch/mips/loongson/fuloong-2e/pci.c
+++ b/arch/mips/loongson/fuloong-2e/pci.c
@@ -55,25 +55,37 @@ static struct pci_controller loongson_pci_controller = {
static void __init ict_pcimap(void)
{
/*
- * local to PCI mapping: [256M,512M] -> [256M,512M]; differ from PMON
+ * local to PCI mapping for CPU accessing PCI space
*
* CPU address space [256M,448M] is window for accessing pci space
- * we set pcimap_lo[0,1,2] to map it to pci space [256M,448M]
- * pcimap: bit18,pcimap_2; bit[17-12],lo2;bit[11-6],lo1;bit[5-0],lo0
+ * we set pcimap_lo[0,1,2] to map it to pci space[0M, 64M], [320M,448M]
+ *
+ * pcimap: PCI_MAP2 PCI_Mem_Lo2 PCI_Mem_Lo1 PCI_Mem_Lo0
+ * [<2G] [384M,448M] [320M,384M] [0M,64M]
*/
- /* 1,00 0110 ,0001 01,00 0000 */
- LOONGSON_PCIMAP = 0x46140;
-
- /* 1, 00 0010, 0000,01, 00 0000 */
- /* LOONGSON_PCIMAP = 0x42040; */
+ LOONGSON_PCIMAP = LOONGSON_PCIMAP_PCIMAP_2 |
+ LOONGSON_PCIMAP_WIN(2, 0x18000000) |
+ LOONGSON_PCIMAP_WIN(1, 0x14000000) |
+ LOONGSON_PCIMAP_WIN(0, 0);
/*
- * PCI to local mapping: [2G,2G+256M] -> [0,256M]
+ * PCI-DMA to local mapping: [2G,2G+256M] -> [0M,256M]
*/
- LOONGSON_PCIBASE0 = 0x80000000;
- LOONGSON_PCIBASE1 = 0x00800000;
- LOONGSON_PCIBASE2 = 0x90000000;
+ LOONGSON_PCIBASE0 = 0x80000000ul; /* base: 2G -> mmap: 0M */
+ /* size: 256M, burst transmission, pre-fetch enable, 64bit */
+ LOONGSON_PCI_HIT0_SEL_L = 0xc000000cul;
+ LOONGSON_PCI_HIT0_SEL_H = 0xfffffffful;
+ LOONGSON_PCI_HIT1_SEL_L = 0x00000006ul; /* set this BAR as invalid */
+ LOONGSON_PCI_HIT1_SEL_H = 0x00000000ul;
+ LOONGSON_PCI_HIT2_SEL_L = 0x00000006ul; /* set this BAR as invalid */
+ LOONGSON_PCI_HIT2_SEL_H = 0x00000000ul;
+
+ /* avoid deadlock of PCI reading/writing lock operation */
+ LOONGSON_PCI_ISR4C = 0xd2000001ul;
+ /* can not change gnt to break pci transfer when device's gnt not
+ deassert for some broken device */
+ LOONGSON_PXARB_CFG = 0x00fe0105ul;
}
static int __init pcibios_init(void)
diff --git a/arch/mips/loongson/fuloong-2e/reset.c
b/arch/mips/loongson/fuloong-2e/reset.c
index 769a2ce..87244a1 100644
--- a/arch/mips/loongson/fuloong-2e/reset.c
+++ b/arch/mips/loongson/fuloong-2e/reset.c
@@ -6,21 +6,24 @@
*
* Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
* Author: Fuxin Zhang, address@hidden
+ *
+ * Copyright (c) 2009 Philippe Vachon <address@hidden>
+ *
+ * Copyright (c) 2009 Lemote, Inc. & Institute of Computing Technology
+ * Author: Wu Zhangjin, address@hidden
*/
#include <linux/pm.h>
#include <asm/reboot.h>
+#include <loongson.h>
static void loongson_restart(char *command)
{
-#ifdef CONFIG_32BIT
- *(unsigned long *)0xbfe00104 &= ~(1 << 2);
- *(unsigned long *)0xbfe00104 |= (1 << 2);
-#else
- *(unsigned long *)0xffffffffbfe00104 &= ~(1 << 2);
- *(unsigned long *)0xffffffffbfe00104 |= (1 << 2);
-#endif
- __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
+ LOONGSON_GENCFG &= ~LOONGSON_GENCFG_CPUSELFRESET;
+ LOONGSON_GENCFG |= LOONGSON_GENCFG_CPUSELFRESET;
+
+ /* reboot via jumping to 0xbfc00000 */
+ ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) ();
}
static void loongson_halt(void)
diff --git a/arch/mips/loongson/fuloong-2e/setup.c
b/arch/mips/loongson/fuloong-2e/setup.c
index 770d7b5..4fcbe48 100644
--- a/arch/mips/loongson/fuloong-2e/setup.c
+++ b/arch/mips/loongson/fuloong-2e/setup.c
@@ -27,7 +27,10 @@ static void loongson_wbflush(void)
asm(".set\tpush\n\t"
".set\tnoreorder\n\t"
".set mips3\n\t"
- "sync\n\t" "nop\n\t" ".set\tpop\n\t" ".set mips0\n\t");
+ "sync\n\t"
+ "nop\n\t"
+ ".set\tpop\n\t"
+ ".set mips0\n\t");
}
void __init loongson_wbflush_setup(void)
--
1.6.2.1
- [Gnewsense-dev] Re: [loongson-PATCH-v1 01/27] fix-warning: incompatible argument type of pci_fixup_irqs, (continued)
[Gnewsense-dev] [loongson-PATCH-v1 02/27] fix-warning: incompatible argument type of virt_to_phys, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 04/27] change the naming methods, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 03/27] fix-error: incompatiable argument type of clear_user, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 05/27] remove reference to bonito64.h, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 09/27] enable Real Time Clock Support for fuloong(2e), wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 06/27] divide the files to the smallest logic unit, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 08/27] clean up the early printk support for fuloong(2e), wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 07/27] replace tons of magic numbers by understandable symbols,
wuzhangjin <=
[Gnewsense-dev] [loongson-PATCH-v1 10/27] add loongson-specific cpu-feature-overrides.h, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 11/27] split the loongson-specific part out, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 12/27] add basic loongson-2f support, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 13/27] add basic fuloong(2f) support, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 14/27] enable serial port support of loongson-based machines, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 15/27] add basic yeeloong(2f) laptop support, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 17/27] define Loongson2F arch specific phys prot access, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 16/27] Add Siliconmotion 712 framebuffer driver, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 18/27] Loongson2 specific OProfile driver, wuzhangjin, 2009/05/21
[Gnewsense-dev] [loongson-PATCH-v1 19/27] flush posted write to irq, wuzhangjin, 2009/05/21