162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2009 Lemote, Inc. 462306a36Sopenharmony_ci * Author: Wu Zhangjin <wuzhangjin@gmail.com> 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef __ASM_MACH_LOONGSON64_LOONGSON_H 862306a36Sopenharmony_ci#define __ASM_MACH_LOONGSON64_LOONGSON_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/io.h> 1162306a36Sopenharmony_ci#include <linux/init.h> 1262306a36Sopenharmony_ci#include <linux/irq.h> 1362306a36Sopenharmony_ci#include <boot_param.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cienum loongson_fw_interface { 1662306a36Sopenharmony_ci LOONGSON_LEFI, 1762306a36Sopenharmony_ci LOONGSON_DTB, 1862306a36Sopenharmony_ci}; 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* machine-specific boot configuration */ 2162306a36Sopenharmony_cistruct loongson_system_configuration { 2262306a36Sopenharmony_ci enum loongson_fw_interface fw_interface; 2362306a36Sopenharmony_ci u32 nr_cpus; 2462306a36Sopenharmony_ci u32 nr_nodes; 2562306a36Sopenharmony_ci int cores_per_node; 2662306a36Sopenharmony_ci int cores_per_package; 2762306a36Sopenharmony_ci u16 boot_cpu_id; 2862306a36Sopenharmony_ci u16 reserved_cpus_mask; 2962306a36Sopenharmony_ci enum loongson_cpu_type cputype; 3062306a36Sopenharmony_ci enum loongson_bridge_type bridgetype; 3162306a36Sopenharmony_ci u64 restart_addr; 3262306a36Sopenharmony_ci u64 poweroff_addr; 3362306a36Sopenharmony_ci u64 suspend_addr; 3462306a36Sopenharmony_ci u64 vgabios_addr; 3562306a36Sopenharmony_ci u32 dma_mask_bits; 3662306a36Sopenharmony_ci u64 workarounds; 3762306a36Sopenharmony_ci void (*early_config)(void); 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* machine-specific reboot/halt operation */ 4162306a36Sopenharmony_ciextern void mach_prepare_reboot(void); 4262306a36Sopenharmony_ciextern void mach_prepare_shutdown(void); 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* environment arguments from bootloader */ 4562306a36Sopenharmony_ciextern u32 cpu_clock_freq; 4662306a36Sopenharmony_ciextern u32 memsize, highmemsize; 4762306a36Sopenharmony_ciextern const struct plat_smp_ops loongson3_smp_ops; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* loongson-specific command line, env and memory initialization */ 5062306a36Sopenharmony_ciextern void __init prom_dtb_init_env(void); 5162306a36Sopenharmony_ciextern void __init prom_lefi_init_env(void); 5262306a36Sopenharmony_ciextern void __init szmem(unsigned int node); 5362306a36Sopenharmony_ciextern void *loongson_fdt_blob; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* irq operation functions */ 5662306a36Sopenharmony_ciextern void mach_irq_dispatch(unsigned int pending); 5762306a36Sopenharmony_ciextern int mach_i8259_irq(void); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* We need this in some places... */ 6062306a36Sopenharmony_ci#define delay() ({ \ 6162306a36Sopenharmony_ci int x; \ 6262306a36Sopenharmony_ci for (x = 0; x < 100000; x++) \ 6362306a36Sopenharmony_ci __asm__ __volatile__(""); \ 6462306a36Sopenharmony_ci}) 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci#define LOONGSON_REG(x) \ 6762306a36Sopenharmony_ci (*(volatile u32 *)((char *)CKSEG1ADDR(LOONGSON_REG_BASE) + (x))) 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define LOONGSON3_REG8(base, x) \ 7062306a36Sopenharmony_ci (*(volatile u8 *)((char *)TO_UNCAC(base) + (x))) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci#define LOONGSON3_REG32(base, x) \ 7362306a36Sopenharmony_ci (*(volatile u32 *)((char *)TO_UNCAC(base) + (x))) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define LOONGSON_FLASH_BASE 0x1c000000 7662306a36Sopenharmony_ci#define LOONGSON_FLASH_SIZE 0x02000000 /* 32M */ 7762306a36Sopenharmony_ci#define LOONGSON_FLASH_TOP (LOONGSON_FLASH_BASE+LOONGSON_FLASH_SIZE-1) 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci#define LOONGSON_LIO0_BASE 0x1e000000 8062306a36Sopenharmony_ci#define LOONGSON_LIO0_SIZE 0x01C00000 /* 28M */ 8162306a36Sopenharmony_ci#define LOONGSON_LIO0_TOP (LOONGSON_LIO0_BASE+LOONGSON_LIO0_SIZE-1) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define LOONGSON_BOOT_BASE 0x1fc00000 8462306a36Sopenharmony_ci#define LOONGSON_BOOT_SIZE 0x00100000 /* 1M */ 8562306a36Sopenharmony_ci#define LOONGSON_BOOT_TOP (LOONGSON_BOOT_BASE+LOONGSON_BOOT_SIZE-1) 8662306a36Sopenharmony_ci#define LOONGSON_REG_BASE 0x1fe00000 8762306a36Sopenharmony_ci#define LOONGSON_REG_SIZE 0x00100000 /* 256Bytes + 256Bytes + ??? */ 8862306a36Sopenharmony_ci#define LOONGSON_REG_TOP (LOONGSON_REG_BASE+LOONGSON_REG_SIZE-1) 8962306a36Sopenharmony_ci/* Loongson-3 specific registers */ 9062306a36Sopenharmony_ci#define LOONGSON3_REG_BASE 0x3ff00000 9162306a36Sopenharmony_ci#define LOONGSON3_REG_SIZE 0x00100000 /* 256Bytes + 256Bytes + ??? */ 9262306a36Sopenharmony_ci#define LOONGSON3_REG_TOP (LOONGSON3_REG_BASE+LOONGSON3_REG_SIZE-1) 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci#define LOONGSON_LIO1_BASE 0x1ff00000 9562306a36Sopenharmony_ci#define LOONGSON_LIO1_SIZE 0x00100000 /* 1M */ 9662306a36Sopenharmony_ci#define LOONGSON_LIO1_TOP (LOONGSON_LIO1_BASE+LOONGSON_LIO1_SIZE-1) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define LOONGSON_PCILO0_BASE 0x10000000 9962306a36Sopenharmony_ci#define LOONGSON_PCILO1_BASE 0x14000000 10062306a36Sopenharmony_ci#define LOONGSON_PCILO2_BASE 0x18000000 10162306a36Sopenharmony_ci#define LOONGSON_PCILO_BASE LOONGSON_PCILO0_BASE 10262306a36Sopenharmony_ci#define LOONGSON_PCILO_SIZE 0x0c000000 /* 64M * 3 */ 10362306a36Sopenharmony_ci#define LOONGSON_PCILO_TOP (LOONGSON_PCILO0_BASE+LOONGSON_PCILO_SIZE-1) 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#define LOONGSON_PCICFG_BASE 0x1fe80000 10662306a36Sopenharmony_ci#define LOONGSON_PCICFG_SIZE 0x00000800 /* 2K */ 10762306a36Sopenharmony_ci#define LOONGSON_PCICFG_TOP (LOONGSON_PCICFG_BASE+LOONGSON_PCICFG_SIZE-1) 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#define LOONGSON_PCIIO_BASE loongson_sysconf.pci_io_base 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci#define LOONGSON_PCIIO_SIZE 0x00100000 /* 1M */ 11262306a36Sopenharmony_ci#define LOONGSON_PCIIO_TOP (LOONGSON_PCIIO_BASE+LOONGSON_PCIIO_SIZE-1) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* Loongson Register Bases */ 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#define LOONGSON_PCICONFIGBASE 0x00 11762306a36Sopenharmony_ci#define LOONGSON_REGBASE 0x100 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* PCI Configuration Registers */ 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci#define LOONGSON_PCI_REG(x) LOONGSON_REG(LOONGSON_PCICONFIGBASE + (x)) 12262306a36Sopenharmony_ci#define LOONGSON_PCIDID LOONGSON_PCI_REG(0x00) 12362306a36Sopenharmony_ci#define LOONGSON_PCICMD LOONGSON_PCI_REG(0x04) 12462306a36Sopenharmony_ci#define LOONGSON_PCICLASS LOONGSON_PCI_REG(0x08) 12562306a36Sopenharmony_ci#define LOONGSON_PCILTIMER LOONGSON_PCI_REG(0x0c) 12662306a36Sopenharmony_ci#define LOONGSON_PCIBASE0 LOONGSON_PCI_REG(0x10) 12762306a36Sopenharmony_ci#define LOONGSON_PCIBASE1 LOONGSON_PCI_REG(0x14) 12862306a36Sopenharmony_ci#define LOONGSON_PCIBASE2 LOONGSON_PCI_REG(0x18) 12962306a36Sopenharmony_ci#define LOONGSON_PCIBASE3 LOONGSON_PCI_REG(0x1c) 13062306a36Sopenharmony_ci#define LOONGSON_PCIBASE4 LOONGSON_PCI_REG(0x20) 13162306a36Sopenharmony_ci#define LOONGSON_PCIEXPRBASE LOONGSON_PCI_REG(0x30) 13262306a36Sopenharmony_ci#define LOONGSON_PCIINT LOONGSON_PCI_REG(0x3c) 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci#define LOONGSON_PCI_ISR4C LOONGSON_PCI_REG(0x4c) 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#define LOONGSON_PCICMD_PERR_CLR 0x80000000 13762306a36Sopenharmony_ci#define LOONGSON_PCICMD_SERR_CLR 0x40000000 13862306a36Sopenharmony_ci#define LOONGSON_PCICMD_MABORT_CLR 0x20000000 13962306a36Sopenharmony_ci#define LOONGSON_PCICMD_MTABORT_CLR 0x10000000 14062306a36Sopenharmony_ci#define LOONGSON_PCICMD_TABORT_CLR 0x08000000 14162306a36Sopenharmony_ci#define LOONGSON_PCICMD_MPERR_CLR 0x01000000 14262306a36Sopenharmony_ci#define LOONGSON_PCICMD_PERRRESPEN 0x00000040 14362306a36Sopenharmony_ci#define LOONGSON_PCICMD_ASTEPEN 0x00000080 14462306a36Sopenharmony_ci#define LOONGSON_PCICMD_SERREN 0x00000100 14562306a36Sopenharmony_ci#define LOONGSON_PCILTIMER_BUSLATENCY 0x0000ff00 14662306a36Sopenharmony_ci#define LOONGSON_PCILTIMER_BUSLATENCY_SHIFT 8 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci/* Loongson h/w Configuration */ 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci#define LOONGSON_GENCFG_OFFSET 0x4 15162306a36Sopenharmony_ci#define LOONGSON_GENCFG LOONGSON_REG(LOONGSON_REGBASE + LOONGSON_GENCFG_OFFSET) 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci#define LOONGSON_GENCFG_DEBUGMODE 0x00000001 15462306a36Sopenharmony_ci#define LOONGSON_GENCFG_SNOOPEN 0x00000002 15562306a36Sopenharmony_ci#define LOONGSON_GENCFG_CPUSELFRESET 0x00000004 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci#define LOONGSON_GENCFG_FORCE_IRQA 0x00000008 15862306a36Sopenharmony_ci#define LOONGSON_GENCFG_IRQA_ISOUT 0x00000010 15962306a36Sopenharmony_ci#define LOONGSON_GENCFG_IRQA_FROM_INT1 0x00000020 16062306a36Sopenharmony_ci#define LOONGSON_GENCFG_BYTESWAP 0x00000040 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define LOONGSON_GENCFG_UNCACHED 0x00000080 16362306a36Sopenharmony_ci#define LOONGSON_GENCFG_PREFETCHEN 0x00000100 16462306a36Sopenharmony_ci#define LOONGSON_GENCFG_WBEHINDEN 0x00000200 16562306a36Sopenharmony_ci#define LOONGSON_GENCFG_CACHEALG 0x00000c00 16662306a36Sopenharmony_ci#define LOONGSON_GENCFG_CACHEALG_SHIFT 10 16762306a36Sopenharmony_ci#define LOONGSON_GENCFG_PCIQUEUE 0x00001000 16862306a36Sopenharmony_ci#define LOONGSON_GENCFG_CACHESTOP 0x00002000 16962306a36Sopenharmony_ci#define LOONGSON_GENCFG_MSTRBYTESWAP 0x00004000 17062306a36Sopenharmony_ci#define LOONGSON_GENCFG_BUSERREN 0x00008000 17162306a36Sopenharmony_ci#define LOONGSON_GENCFG_NORETRYTIMEOUT 0x00010000 17262306a36Sopenharmony_ci#define LOONGSON_GENCFG_SHORTCOPYTIMEOUT 0x00020000 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/* PCI address map control */ 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci#define LOONGSON_PCIMAP LOONGSON_REG(LOONGSON_REGBASE + 0x10) 17762306a36Sopenharmony_ci#define LOONGSON_PCIMEMBASECFG LOONGSON_REG(LOONGSON_REGBASE + 0x14) 17862306a36Sopenharmony_ci#define LOONGSON_PCIMAP_CFG LOONGSON_REG(LOONGSON_REGBASE + 0x18) 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci/* GPIO Regs - r/w */ 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci#define LOONGSON_GPIODATA LOONGSON_REG(LOONGSON_REGBASE + 0x1c) 18362306a36Sopenharmony_ci#define LOONGSON_GPIOIE LOONGSON_REG(LOONGSON_REGBASE + 0x20) 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/* ICU Configuration Regs - r/w */ 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci#define LOONGSON_INTEDGE LOONGSON_REG(LOONGSON_REGBASE + 0x24) 18862306a36Sopenharmony_ci#define LOONGSON_INTSTEER LOONGSON_REG(LOONGSON_REGBASE + 0x28) 18962306a36Sopenharmony_ci#define LOONGSON_INTPOL LOONGSON_REG(LOONGSON_REGBASE + 0x2c) 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci/* ICU Enable Regs - IntEn & IntISR are r/o. */ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define LOONGSON_INTENSET LOONGSON_REG(LOONGSON_REGBASE + 0x30) 19462306a36Sopenharmony_ci#define LOONGSON_INTENCLR LOONGSON_REG(LOONGSON_REGBASE + 0x34) 19562306a36Sopenharmony_ci#define LOONGSON_INTEN LOONGSON_REG(LOONGSON_REGBASE + 0x38) 19662306a36Sopenharmony_ci#define LOONGSON_INTISR LOONGSON_REG(LOONGSON_REGBASE + 0x3c) 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci/* ICU */ 19962306a36Sopenharmony_ci#define LOONGSON_ICU_MBOXES 0x0000000f 20062306a36Sopenharmony_ci#define LOONGSON_ICU_MBOXES_SHIFT 0 20162306a36Sopenharmony_ci#define LOONGSON_ICU_DMARDY 0x00000010 20262306a36Sopenharmony_ci#define LOONGSON_ICU_DMAEMPTY 0x00000020 20362306a36Sopenharmony_ci#define LOONGSON_ICU_COPYRDY 0x00000040 20462306a36Sopenharmony_ci#define LOONGSON_ICU_COPYEMPTY 0x00000080 20562306a36Sopenharmony_ci#define LOONGSON_ICU_COPYERR 0x00000100 20662306a36Sopenharmony_ci#define LOONGSON_ICU_PCIIRQ 0x00000200 20762306a36Sopenharmony_ci#define LOONGSON_ICU_MASTERERR 0x00000400 20862306a36Sopenharmony_ci#define LOONGSON_ICU_SYSTEMERR 0x00000800 20962306a36Sopenharmony_ci#define LOONGSON_ICU_DRAMPERR 0x00001000 21062306a36Sopenharmony_ci#define LOONGSON_ICU_RETRYERR 0x00002000 21162306a36Sopenharmony_ci#define LOONGSON_ICU_GPIOS 0x01ff0000 21262306a36Sopenharmony_ci#define LOONGSON_ICU_GPIOS_SHIFT 16 21362306a36Sopenharmony_ci#define LOONGSON_ICU_GPINS 0x7e000000 21462306a36Sopenharmony_ci#define LOONGSON_ICU_GPINS_SHIFT 25 21562306a36Sopenharmony_ci#define LOONGSON_ICU_MBOX(N) (1<<(LOONGSON_ICU_MBOXES_SHIFT+(N))) 21662306a36Sopenharmony_ci#define LOONGSON_ICU_GPIO(N) (1<<(LOONGSON_ICU_GPIOS_SHIFT+(N))) 21762306a36Sopenharmony_ci#define LOONGSON_ICU_GPIN(N) (1<<(LOONGSON_ICU_GPINS_SHIFT+(N))) 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci/* PCI prefetch window base & mask */ 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci#define LOONGSON_MEM_WIN_BASE_L LOONGSON_REG(LOONGSON_REGBASE + 0x40) 22262306a36Sopenharmony_ci#define LOONGSON_MEM_WIN_BASE_H LOONGSON_REG(LOONGSON_REGBASE + 0x44) 22362306a36Sopenharmony_ci#define LOONGSON_MEM_WIN_MASK_L LOONGSON_REG(LOONGSON_REGBASE + 0x48) 22462306a36Sopenharmony_ci#define LOONGSON_MEM_WIN_MASK_H LOONGSON_REG(LOONGSON_REGBASE + 0x4c) 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci/* PCI_Hit*_Sel_* */ 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci#define LOONGSON_PCI_HIT0_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x50) 22962306a36Sopenharmony_ci#define LOONGSON_PCI_HIT0_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x54) 23062306a36Sopenharmony_ci#define LOONGSON_PCI_HIT1_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x58) 23162306a36Sopenharmony_ci#define LOONGSON_PCI_HIT1_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x5c) 23262306a36Sopenharmony_ci#define LOONGSON_PCI_HIT2_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x60) 23362306a36Sopenharmony_ci#define LOONGSON_PCI_HIT2_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x64) 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci/* PXArb Config & Status */ 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci#define LOONGSON_PXARB_CFG LOONGSON_REG(LOONGSON_REGBASE + 0x68) 23862306a36Sopenharmony_ci#define LOONGSON_PXARB_STATUS LOONGSON_REG(LOONGSON_REGBASE + 0x6c) 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci#define MAX_PACKAGES 4 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci/* Chip Config registor of each physical cpu package, PRid >= Loongson-2F */ 24362306a36Sopenharmony_ciextern u64 loongson_chipcfg[MAX_PACKAGES]; 24462306a36Sopenharmony_ci#define LOONGSON_CHIPCFG(id) (*(volatile u32 *)(loongson_chipcfg[id])) 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci/* Chip Temperature registor of each physical cpu package, PRid >= Loongson-3A */ 24762306a36Sopenharmony_ciextern u64 loongson_chiptemp[MAX_PACKAGES]; 24862306a36Sopenharmony_ci#define LOONGSON_CHIPTEMP(id) (*(volatile u32 *)(loongson_chiptemp[id])) 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci/* Freq Control register of each physical cpu package, PRid >= Loongson-3B */ 25162306a36Sopenharmony_ciextern u64 loongson_freqctrl[MAX_PACKAGES]; 25262306a36Sopenharmony_ci#define LOONGSON_FREQCTRL(id) (*(volatile u32 *)(loongson_freqctrl[id])) 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci/* pcimap */ 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO0 0x0000003f 25762306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO0_SHIFT 0 25862306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO1 0x00000fc0 25962306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO1_SHIFT 6 26062306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO2 0x0003f000 26162306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO2_SHIFT 12 26262306a36Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_2 0x00040000 26362306a36Sopenharmony_ci#define LOONGSON_PCIMAP_WIN(WIN, ADDR) \ 26462306a36Sopenharmony_ci ((((ADDR)>>26) & LOONGSON_PCIMAP_PCIMAP_LO0) << ((WIN)*6)) 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci#endif /* __ASM_MACH_LOONGSON64_LOONGSON_H */ 267