Skip to content

Commit

Permalink
MIPS: Loongson: Split common loongson source code out
Browse files Browse the repository at this point in the history
To share common loongson source code between all of the loongson-based
machines. there is a need to split it out of the fuloong-2e/ directory.
at the same time, other according tuning is needed. the machine-specific
parts are defined as macros in relative header file, pci.h, mem.h,
machine.h.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  • Loading branch information
Wu Zhangjin authored and Ralf Baechle committed Sep 17, 2009
1 parent 8e49711 commit 85749d2
Show file tree
Hide file tree
Showing 24 changed files with 351 additions and 133 deletions.
32 changes: 9 additions & 23 deletions arch/mips/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,15 @@ config LASAT
select SYS_SUPPORTS_64BIT_KERNEL if BROKEN
select SYS_SUPPORTS_LITTLE_ENDIAN

config LEMOTE_FULOONG2E
bool "Lemote Fuloong2e mini-PC"
select ARCH_SPARSEMEM_ENABLE
select CEVT_R4K
select CSRC_R4K
select SYS_HAS_CPU_LOONGSON2
select DMA_NONCOHERENT
select BOOT_ELF32
select BOARD_SCACHE
select HAVE_STD_PC_SERIAL_PORT
select HW_HAS_PCI
select I8259
select ISA
select IRQ_CPU
select SYS_SUPPORTS_32BIT_KERNEL
select SYS_SUPPORTS_64BIT_KERNEL
select SYS_SUPPORTS_LITTLE_ENDIAN
select SYS_SUPPORTS_HIGHMEM
select SYS_HAS_EARLY_PRINTK
select GENERIC_ISA_DMA_SUPPORT_BROKEN
select CPU_HAS_WB
config MACH_LOONGSON
bool "Loongson family of machines"
help
Lemote Fuloong2e mini-PC board based on the Chinese Loongson-2E CPU and
an FPGA northbridge
This enables the support of Loongson family of machines.

Loongson is a family of general-purpose MIPS-compatible CPUs.
developed at Institute of Computing Technology (ICT),
Chinese Academy of Sciences (CAS) in the People's Republic
of China. The chief architect is Professor Weiwu Hu.

config MIPS_MALTA
bool "MIPS Malta board"
Expand Down Expand Up @@ -668,6 +653,7 @@ source "arch/mips/sibyte/Kconfig"
source "arch/mips/txx9/Kconfig"
source "arch/mips/vr41xx/Kconfig"
source "arch/mips/cavium-octeon/Kconfig"
source "arch/mips/loongson/Kconfig"

endmenu

Expand Down
7 changes: 4 additions & 3 deletions arch/mips/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ cflags-$(CONFIG_WR_PPMC) += -I$(srctree)/arch/mips/include/asm/mach-wrppmc
load-$(CONFIG_WR_PPMC) += 0xffffffff80100000

#
# lemote fuloong2e mini-PC board
# Loongson family
#
core-$(CONFIG_LEMOTE_FULOONG2E) +=arch/mips/loongson/fuloong-2e/
core-$(CONFIG_MACH_LOONGSON) +=arch/mips/loongson/
cflags-$(CONFIG_MACH_LOONGSON) += -I$(srctree)/arch/mips/include/asm/mach-loongson \
-mno-branch-likely
load-$(CONFIG_LEMOTE_FULOONG2E) +=0xffffffff80100000
cflags-$(CONFIG_LEMOTE_FULOONG2E) += -I$(srctree)/arch/mips/include/asm/mach-loongson/

#
# MIPS Malta board
Expand Down
11 changes: 11 additions & 0 deletions arch/mips/include/asm/mach-loongson/loongson.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/* loongson internal northbridge initialization */
extern void bonito_irq_init(void);

/* machine-specific reboot/halt operation */
extern void mach_prepare_reboot(void);
extern void mach_prepare_shutdown(void);

/* environment arguments from bootloader */
extern unsigned long bus_clock, cpu_clock_freq;
extern unsigned long memsize, highmemsize;
Expand All @@ -30,6 +34,13 @@ extern void __init prom_init_memory(void);
extern void __init prom_init_cmdline(void);
extern void __init prom_init_env(void);

/* irq operation functions */
extern void bonito_irqdispatch(void);
extern void __init bonito_irq_init(void);
extern void __init set_irq_trigger_mode(void);
extern void __init mach_init_irq(void);
extern void mach_irq_dispatch(unsigned int pending);

/* PCI Configuration Registers */
#define LOONGSON_PCI_ISR4C BONITO_PCI_REG(0x4c)

Expand Down
22 changes: 22 additions & 0 deletions arch/mips/include/asm/mach-loongson/machine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2009 Lemote, Inc. & Institute of Computing Technology
* Author: Wu Zhangjin <wuzj@lemote.com>
*
* 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 __ASM_MACH_LOONGSON_MACHINE_H
#define __ASM_MACH_LOONGSON_MACHINE_H

#ifdef CONFIG_LEMOTE_FULOONG2E

#define LOONGSON_UART_BASE (BONITO_PCIIO_BASE + 0x3f8)

#define LOONGSON_MACHNAME "lemote-fuloong-2e-box"

#endif

#endif /* __ASM_MACH_LOONGSON_MACHINE_H */
30 changes: 30 additions & 0 deletions arch/mips/include/asm/mach-loongson/mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2009 Lemote, Inc. & Institute of Computing Technology
* Author: Wu Zhangjin <wuzj@lemote.com>
*
* 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 __ASM_MACH_LOONGSON_MEM_H
#define __ASM_MACH_LOONGSON_MEM_H

/*
* On Lemote Loongson 2e
*
* the high memory space starts from 512M.
* the peripheral registers reside between 0x1000:0000 and 0x2000:0000.
*/

#ifdef CONFIG_LEMOTE_FULOONG2E

#define LOONGSON_HIGHMEM_START 0x20000000

#define LOONGSON_MMIO_MEM_START 0x10000000
#define LOONGSON_MMIO_MEM_END 0x20000000

#endif

#endif /* __ASM_MACH_LOONGSON_MEM_H */
12 changes: 9 additions & 3 deletions arch/mips/include/asm/mach-loongson/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@

extern struct pci_ops bonito64_pci_ops;

#define LOONGSON2E_PCI_MEM_START BONITO_PCILO1_BASE
#define LOONGSON2E_PCI_MEM_END (BONITO_PCILO1_BASE + 0x04000000 * 2)
#define LOONGSON2E_PCI_IO_START 0x00004000UL
#ifdef CONFIG_LEMOTE_FULOONG2E

/* this pci memory space is mapped by pcimap in pci.c */
#define LOONGSON_PCI_MEM_START BONITO_PCILO1_BASE
#define LOONGSON_PCI_MEM_END (BONITO_PCILO1_BASE + 0x04000000 * 2)
/* this is an offset from mips_io_port_base */
#define LOONGSON_PCI_IO_START 0x00004000UL

#endif

#endif /* !__ASM_MACH_LOONGSON_PCI_H_ */
31 changes: 31 additions & 0 deletions arch/mips/loongson/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
choice
prompt "Machine Type"
depends on MACH_LOONGSON

config LEMOTE_FULOONG2E
bool "Lemote Fuloong(2e) mini-PC"
select ARCH_SPARSEMEM_ENABLE
select CEVT_R4K
select CSRC_R4K
select SYS_HAS_CPU_LOONGSON2
select DMA_NONCOHERENT
select BOOT_ELF32
select BOARD_SCACHE
select HW_HAS_PCI
select I8259
select ISA
select IRQ_CPU
select SYS_SUPPORTS_32BIT_KERNEL
select SYS_SUPPORTS_64BIT_KERNEL
select SYS_SUPPORTS_LITTLE_ENDIAN
select SYS_SUPPORTS_HIGHMEM
select SYS_HAS_EARLY_PRINTK
select GENERIC_HARDIRQS_NO__DO_IRQ
select GENERIC_ISA_DMA_SUPPORT_BROKEN
select CPU_HAS_WB
help
Lemote Fuloong(2e) mini-PC board based on the Chinese Loongson-2E CPU and
an FPGA northbridge

Lemote Fuloong(2e) mini PC have a VIA686B south bridge.
endchoice
11 changes: 11 additions & 0 deletions arch/mips/loongson/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Common code for all Loongson based systems
#

obj-$(CONFIG_MACH_LOONGSON) += common/

#
# Lemote Fuloong mini-PC (Loongson 2E-based)
#

obj-$(CONFIG_LEMOTE_FULOONG2E) += fuloong-2e/
11 changes: 11 additions & 0 deletions arch/mips/loongson/common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Makefile for loongson based machines.
#

obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \
pci.o bonito-irq.o mem.o

#
# Early printk support
#
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#include <linux/serial_reg.h>

#include <loongson.h>

#define UART_BASE (BONITO_PCIIO_BASE + 0x3f8)
#include <machine.h>

#define PORT(base, offset) (u8 *)(base + offset)

Expand All @@ -30,7 +29,7 @@ static inline void serial_out(phys_addr_t base, int offset, int value)
void prom_putchar(char c)
{
phys_addr_t uart_base =
(phys_addr_t) ioremap_nocache(UART_BASE, 8);
(phys_addr_t) ioremap_nocache(LOONGSON_UART_BASE, 8);

while ((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0)
;
Expand Down
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions arch/mips/loongson/common/irq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
* Author: Fuxin Zhang, zhangfx@lemote.com
*
* 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.
*/
#include <linux/delay.h>
#include <linux/interrupt.h>

#include <loongson.h>
/*
* the first level int-handler will jump here if it is a bonito irq
*/
void bonito_irqdispatch(void)
{
u32 int_status;
int i;

/* workaround the IO dma problem: let cpu looping to allow DMA finish */
int_status = BONITO_INTISR;
if (int_status & (1 << 10)) {
while (int_status & (1 << 10)) {
udelay(1);
int_status = BONITO_INTISR;
}
}

/* Get pending sources, masked by current enables */
int_status = BONITO_INTISR & BONITO_INTEN;

if (int_status != 0) {
i = __ffs(int_status);
int_status &= ~(1 << i);
do_IRQ(BONITO_IRQ_BASE + i);
}
}

asmlinkage void plat_irq_dispatch(void)
{
unsigned int pending;

pending = read_c0_cause() & read_c0_status() & ST0_IM;

/* machine-specific plat_irq_dispatch */
mach_irq_dispatch(pending);
}

void __init arch_init_irq(void)
{
/*
* Clear all of the interrupts while we change the able around a bit.
* int-handler is not on bootstrap
*/
clear_c0_status(ST0_IM | ST0_BEV);
local_irq_disable();

/* setting irq trigger mode */
set_irq_trigger_mode();

/* no steer */
BONITO_INTSTEER = 0;

/*
* Mask out all interrupt by writing "1" to all bit position in
* the interrupt reset reg.
*/
BONITO_INTENCLR = ~0;

/* machine specific irq init */
mach_init_irq();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
* option) any later version.
*/

#include <machine.h>

const char *get_system_type(void)
{
return "lemote-fuloong-2e-box";
return LOONGSON_MACHNAME;
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#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, highmemsize << 20, BOOT_MEM_RAM);
add_memory_region(LOONGSON_HIGHMEM_START,
highmemsize << 20, BOOT_MEM_RAM);
#endif /* CONFIG_64BIT */
}

Expand All @@ -27,10 +29,7 @@ int __uncached_access(struct file *file, unsigned long addr)
if (file->f_flags & O_SYNC)
return 1;

/*
* 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));
((addr >= LOONGSON_MMIO_MEM_START) &&
(addr < LOONGSON_MMIO_MEM_END));
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
#include <pci.h>
#include <loongson.h>

static struct resource loongson2e_pci_mem_resource = {
.name = "LOONGSON2E PCI MEM",
.start = LOONGSON2E_PCI_MEM_START,
.end = LOONGSON2E_PCI_MEM_END,
static struct resource loongson_pci_mem_resource = {
.name = "pci memory space",
.start = LOONGSON_PCI_MEM_START,
.end = LOONGSON_PCI_MEM_END,
.flags = IORESOURCE_MEM,
};

static struct resource loongson2e_pci_io_resource = {
.name = "LOONGSON2E PCI IO MEM",
.start = LOONGSON2E_PCI_IO_START,
static struct resource loongson_pci_io_resource = {
.name = "pci io space",
.start = LOONGSON_PCI_IO_START,
.end = IO_SPACE_LIMIT,
.flags = IORESOURCE_IO,
};

static struct pci_controller loongson2e_pci_controller = {
static struct pci_controller loongson_pci_controller = {
.pci_ops = &bonito64_pci_ops,
.io_resource = &loongson2e_pci_io_resource,
.mem_resource = &loongson2e_pci_mem_resource,
.io_resource = &loongson_pci_io_resource,
.mem_resource = &loongson_pci_mem_resource,
.mem_offset = 0x00000000UL,
.io_offset = 0x00000000UL,
};
Expand Down Expand Up @@ -73,9 +73,9 @@ static int __init pcibios_init(void)
{
setup_pcimap();

loongson2e_pci_controller.io_map_base = mips_io_port_base;
loongson_pci_controller.io_map_base = mips_io_port_base;

register_pci_controller(&loongson2e_pci_controller);
register_pci_controller(&loongson_pci_controller);

return 0;
}
Expand Down
Loading

0 comments on commit 85749d2

Please sign in to comment.