18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2009 Lemote, Inc. 48c2ecf20Sopenharmony_ci * Author: Wu Zhangjin <wuzhangjin@gmail.com> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __ASM_MACH_LOONGSON64_LOONGSON_H 88c2ecf20Sopenharmony_ci#define __ASM_MACH_LOONGSON64_LOONGSON_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/io.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/irq.h> 138c2ecf20Sopenharmony_ci#include <boot_param.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* machine-specific reboot/halt operation */ 178c2ecf20Sopenharmony_ciextern void mach_prepare_reboot(void); 188c2ecf20Sopenharmony_ciextern void mach_prepare_shutdown(void); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* environment arguments from bootloader */ 218c2ecf20Sopenharmony_ciextern u32 cpu_clock_freq; 228c2ecf20Sopenharmony_ciextern u32 memsize, highmemsize; 238c2ecf20Sopenharmony_ciextern const struct plat_smp_ops loongson3_smp_ops; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* loongson-specific command line, env and memory initialization */ 268c2ecf20Sopenharmony_ciextern void __init prom_init_memory(void); 278c2ecf20Sopenharmony_ciextern void __init prom_init_env(void); 288c2ecf20Sopenharmony_ciextern void *loongson_fdt_blob; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* irq operation functions */ 318c2ecf20Sopenharmony_ciextern void mach_irq_dispatch(unsigned int pending); 328c2ecf20Sopenharmony_ciextern int mach_i8259_irq(void); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* We need this in some places... */ 358c2ecf20Sopenharmony_ci#define delay() ({ \ 368c2ecf20Sopenharmony_ci int x; \ 378c2ecf20Sopenharmony_ci for (x = 0; x < 100000; x++) \ 388c2ecf20Sopenharmony_ci __asm__ __volatile__(""); \ 398c2ecf20Sopenharmony_ci}) 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define LOONGSON_REG(x) \ 428c2ecf20Sopenharmony_ci (*(volatile u32 *)((char *)CKSEG1ADDR(LOONGSON_REG_BASE) + (x))) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define LOONGSON3_REG8(base, x) \ 458c2ecf20Sopenharmony_ci (*(volatile u8 *)((char *)TO_UNCAC(base) + (x))) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define LOONGSON3_REG32(base, x) \ 488c2ecf20Sopenharmony_ci (*(volatile u32 *)((char *)TO_UNCAC(base) + (x))) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define LOONGSON_FLASH_BASE 0x1c000000 518c2ecf20Sopenharmony_ci#define LOONGSON_FLASH_SIZE 0x02000000 /* 32M */ 528c2ecf20Sopenharmony_ci#define LOONGSON_FLASH_TOP (LOONGSON_FLASH_BASE+LOONGSON_FLASH_SIZE-1) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define LOONGSON_LIO0_BASE 0x1e000000 558c2ecf20Sopenharmony_ci#define LOONGSON_LIO0_SIZE 0x01C00000 /* 28M */ 568c2ecf20Sopenharmony_ci#define LOONGSON_LIO0_TOP (LOONGSON_LIO0_BASE+LOONGSON_LIO0_SIZE-1) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define LOONGSON_BOOT_BASE 0x1fc00000 598c2ecf20Sopenharmony_ci#define LOONGSON_BOOT_SIZE 0x00100000 /* 1M */ 608c2ecf20Sopenharmony_ci#define LOONGSON_BOOT_TOP (LOONGSON_BOOT_BASE+LOONGSON_BOOT_SIZE-1) 618c2ecf20Sopenharmony_ci#define LOONGSON_REG_BASE 0x1fe00000 628c2ecf20Sopenharmony_ci#define LOONGSON_REG_SIZE 0x00100000 /* 256Bytes + 256Bytes + ??? */ 638c2ecf20Sopenharmony_ci#define LOONGSON_REG_TOP (LOONGSON_REG_BASE+LOONGSON_REG_SIZE-1) 648c2ecf20Sopenharmony_ci/* Loongson-3 specific registers */ 658c2ecf20Sopenharmony_ci#define LOONGSON3_REG_BASE 0x3ff00000 668c2ecf20Sopenharmony_ci#define LOONGSON3_REG_SIZE 0x00100000 /* 256Bytes + 256Bytes + ??? */ 678c2ecf20Sopenharmony_ci#define LOONGSON3_REG_TOP (LOONGSON3_REG_BASE+LOONGSON3_REG_SIZE-1) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define LOONGSON_LIO1_BASE 0x1ff00000 708c2ecf20Sopenharmony_ci#define LOONGSON_LIO1_SIZE 0x00100000 /* 1M */ 718c2ecf20Sopenharmony_ci#define LOONGSON_LIO1_TOP (LOONGSON_LIO1_BASE+LOONGSON_LIO1_SIZE-1) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define LOONGSON_PCILO0_BASE 0x10000000 748c2ecf20Sopenharmony_ci#define LOONGSON_PCILO1_BASE 0x14000000 758c2ecf20Sopenharmony_ci#define LOONGSON_PCILO2_BASE 0x18000000 768c2ecf20Sopenharmony_ci#define LOONGSON_PCILO_BASE LOONGSON_PCILO0_BASE 778c2ecf20Sopenharmony_ci#define LOONGSON_PCILO_SIZE 0x0c000000 /* 64M * 3 */ 788c2ecf20Sopenharmony_ci#define LOONGSON_PCILO_TOP (LOONGSON_PCILO0_BASE+LOONGSON_PCILO_SIZE-1) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define LOONGSON_PCICFG_BASE 0x1fe80000 818c2ecf20Sopenharmony_ci#define LOONGSON_PCICFG_SIZE 0x00000800 /* 2K */ 828c2ecf20Sopenharmony_ci#define LOONGSON_PCICFG_TOP (LOONGSON_PCICFG_BASE+LOONGSON_PCICFG_SIZE-1) 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define LOONGSON_PCIIO_BASE loongson_sysconf.pci_io_base 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define LOONGSON_PCIIO_SIZE 0x00100000 /* 1M */ 878c2ecf20Sopenharmony_ci#define LOONGSON_PCIIO_TOP (LOONGSON_PCIIO_BASE+LOONGSON_PCIIO_SIZE-1) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* Loongson Register Bases */ 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define LOONGSON_PCICONFIGBASE 0x00 928c2ecf20Sopenharmony_ci#define LOONGSON_REGBASE 0x100 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* PCI Configuration Registers */ 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#define LOONGSON_PCI_REG(x) LOONGSON_REG(LOONGSON_PCICONFIGBASE + (x)) 978c2ecf20Sopenharmony_ci#define LOONGSON_PCIDID LOONGSON_PCI_REG(0x00) 988c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD LOONGSON_PCI_REG(0x04) 998c2ecf20Sopenharmony_ci#define LOONGSON_PCICLASS LOONGSON_PCI_REG(0x08) 1008c2ecf20Sopenharmony_ci#define LOONGSON_PCILTIMER LOONGSON_PCI_REG(0x0c) 1018c2ecf20Sopenharmony_ci#define LOONGSON_PCIBASE0 LOONGSON_PCI_REG(0x10) 1028c2ecf20Sopenharmony_ci#define LOONGSON_PCIBASE1 LOONGSON_PCI_REG(0x14) 1038c2ecf20Sopenharmony_ci#define LOONGSON_PCIBASE2 LOONGSON_PCI_REG(0x18) 1048c2ecf20Sopenharmony_ci#define LOONGSON_PCIBASE3 LOONGSON_PCI_REG(0x1c) 1058c2ecf20Sopenharmony_ci#define LOONGSON_PCIBASE4 LOONGSON_PCI_REG(0x20) 1068c2ecf20Sopenharmony_ci#define LOONGSON_PCIEXPRBASE LOONGSON_PCI_REG(0x30) 1078c2ecf20Sopenharmony_ci#define LOONGSON_PCIINT LOONGSON_PCI_REG(0x3c) 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#define LOONGSON_PCI_ISR4C LOONGSON_PCI_REG(0x4c) 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_PERR_CLR 0x80000000 1128c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_SERR_CLR 0x40000000 1138c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_MABORT_CLR 0x20000000 1148c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_MTABORT_CLR 0x10000000 1158c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_TABORT_CLR 0x08000000 1168c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_MPERR_CLR 0x01000000 1178c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_PERRRESPEN 0x00000040 1188c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_ASTEPEN 0x00000080 1198c2ecf20Sopenharmony_ci#define LOONGSON_PCICMD_SERREN 0x00000100 1208c2ecf20Sopenharmony_ci#define LOONGSON_PCILTIMER_BUSLATENCY 0x0000ff00 1218c2ecf20Sopenharmony_ci#define LOONGSON_PCILTIMER_BUSLATENCY_SHIFT 8 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* Loongson h/w Configuration */ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_OFFSET 0x4 1268c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG LOONGSON_REG(LOONGSON_REGBASE + LOONGSON_GENCFG_OFFSET) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_DEBUGMODE 0x00000001 1298c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_SNOOPEN 0x00000002 1308c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_CPUSELFRESET 0x00000004 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_FORCE_IRQA 0x00000008 1338c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_IRQA_ISOUT 0x00000010 1348c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_IRQA_FROM_INT1 0x00000020 1358c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_BYTESWAP 0x00000040 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_UNCACHED 0x00000080 1388c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_PREFETCHEN 0x00000100 1398c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_WBEHINDEN 0x00000200 1408c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_CACHEALG 0x00000c00 1418c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_CACHEALG_SHIFT 10 1428c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_PCIQUEUE 0x00001000 1438c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_CACHESTOP 0x00002000 1448c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_MSTRBYTESWAP 0x00004000 1458c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_BUSERREN 0x00008000 1468c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_NORETRYTIMEOUT 0x00010000 1478c2ecf20Sopenharmony_ci#define LOONGSON_GENCFG_SHORTCOPYTIMEOUT 0x00020000 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* PCI address map control */ 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP LOONGSON_REG(LOONGSON_REGBASE + 0x10) 1528c2ecf20Sopenharmony_ci#define LOONGSON_PCIMEMBASECFG LOONGSON_REG(LOONGSON_REGBASE + 0x14) 1538c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_CFG LOONGSON_REG(LOONGSON_REGBASE + 0x18) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/* GPIO Regs - r/w */ 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci#define LOONGSON_GPIODATA LOONGSON_REG(LOONGSON_REGBASE + 0x1c) 1588c2ecf20Sopenharmony_ci#define LOONGSON_GPIOIE LOONGSON_REG(LOONGSON_REGBASE + 0x20) 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/* ICU Configuration Regs - r/w */ 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#define LOONGSON_INTEDGE LOONGSON_REG(LOONGSON_REGBASE + 0x24) 1638c2ecf20Sopenharmony_ci#define LOONGSON_INTSTEER LOONGSON_REG(LOONGSON_REGBASE + 0x28) 1648c2ecf20Sopenharmony_ci#define LOONGSON_INTPOL LOONGSON_REG(LOONGSON_REGBASE + 0x2c) 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci/* ICU Enable Regs - IntEn & IntISR are r/o. */ 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci#define LOONGSON_INTENSET LOONGSON_REG(LOONGSON_REGBASE + 0x30) 1698c2ecf20Sopenharmony_ci#define LOONGSON_INTENCLR LOONGSON_REG(LOONGSON_REGBASE + 0x34) 1708c2ecf20Sopenharmony_ci#define LOONGSON_INTEN LOONGSON_REG(LOONGSON_REGBASE + 0x38) 1718c2ecf20Sopenharmony_ci#define LOONGSON_INTISR LOONGSON_REG(LOONGSON_REGBASE + 0x3c) 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci/* ICU */ 1748c2ecf20Sopenharmony_ci#define LOONGSON_ICU_MBOXES 0x0000000f 1758c2ecf20Sopenharmony_ci#define LOONGSON_ICU_MBOXES_SHIFT 0 1768c2ecf20Sopenharmony_ci#define LOONGSON_ICU_DMARDY 0x00000010 1778c2ecf20Sopenharmony_ci#define LOONGSON_ICU_DMAEMPTY 0x00000020 1788c2ecf20Sopenharmony_ci#define LOONGSON_ICU_COPYRDY 0x00000040 1798c2ecf20Sopenharmony_ci#define LOONGSON_ICU_COPYEMPTY 0x00000080 1808c2ecf20Sopenharmony_ci#define LOONGSON_ICU_COPYERR 0x00000100 1818c2ecf20Sopenharmony_ci#define LOONGSON_ICU_PCIIRQ 0x00000200 1828c2ecf20Sopenharmony_ci#define LOONGSON_ICU_MASTERERR 0x00000400 1838c2ecf20Sopenharmony_ci#define LOONGSON_ICU_SYSTEMERR 0x00000800 1848c2ecf20Sopenharmony_ci#define LOONGSON_ICU_DRAMPERR 0x00001000 1858c2ecf20Sopenharmony_ci#define LOONGSON_ICU_RETRYERR 0x00002000 1868c2ecf20Sopenharmony_ci#define LOONGSON_ICU_GPIOS 0x01ff0000 1878c2ecf20Sopenharmony_ci#define LOONGSON_ICU_GPIOS_SHIFT 16 1888c2ecf20Sopenharmony_ci#define LOONGSON_ICU_GPINS 0x7e000000 1898c2ecf20Sopenharmony_ci#define LOONGSON_ICU_GPINS_SHIFT 25 1908c2ecf20Sopenharmony_ci#define LOONGSON_ICU_MBOX(N) (1<<(LOONGSON_ICU_MBOXES_SHIFT+(N))) 1918c2ecf20Sopenharmony_ci#define LOONGSON_ICU_GPIO(N) (1<<(LOONGSON_ICU_GPIOS_SHIFT+(N))) 1928c2ecf20Sopenharmony_ci#define LOONGSON_ICU_GPIN(N) (1<<(LOONGSON_ICU_GPINS_SHIFT+(N))) 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci/* PCI prefetch window base & mask */ 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#define LOONGSON_MEM_WIN_BASE_L LOONGSON_REG(LOONGSON_REGBASE + 0x40) 1978c2ecf20Sopenharmony_ci#define LOONGSON_MEM_WIN_BASE_H LOONGSON_REG(LOONGSON_REGBASE + 0x44) 1988c2ecf20Sopenharmony_ci#define LOONGSON_MEM_WIN_MASK_L LOONGSON_REG(LOONGSON_REGBASE + 0x48) 1998c2ecf20Sopenharmony_ci#define LOONGSON_MEM_WIN_MASK_H LOONGSON_REG(LOONGSON_REGBASE + 0x4c) 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* PCI_Hit*_Sel_* */ 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#define LOONGSON_PCI_HIT0_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x50) 2048c2ecf20Sopenharmony_ci#define LOONGSON_PCI_HIT0_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x54) 2058c2ecf20Sopenharmony_ci#define LOONGSON_PCI_HIT1_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x58) 2068c2ecf20Sopenharmony_ci#define LOONGSON_PCI_HIT1_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x5c) 2078c2ecf20Sopenharmony_ci#define LOONGSON_PCI_HIT2_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x60) 2088c2ecf20Sopenharmony_ci#define LOONGSON_PCI_HIT2_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x64) 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* PXArb Config & Status */ 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#define LOONGSON_PXARB_CFG LOONGSON_REG(LOONGSON_REGBASE + 0x68) 2138c2ecf20Sopenharmony_ci#define LOONGSON_PXARB_STATUS LOONGSON_REG(LOONGSON_REGBASE + 0x6c) 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci#define MAX_PACKAGES 4 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci/* Chip Config registor of each physical cpu package, PRid >= Loongson-2F */ 2188c2ecf20Sopenharmony_ciextern u64 loongson_chipcfg[MAX_PACKAGES]; 2198c2ecf20Sopenharmony_ci#define LOONGSON_CHIPCFG(id) (*(volatile u32 *)(loongson_chipcfg[id])) 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci/* Chip Temperature registor of each physical cpu package, PRid >= Loongson-3A */ 2228c2ecf20Sopenharmony_ciextern u64 loongson_chiptemp[MAX_PACKAGES]; 2238c2ecf20Sopenharmony_ci#define LOONGSON_CHIPTEMP(id) (*(volatile u32 *)(loongson_chiptemp[id])) 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci/* Freq Control register of each physical cpu package, PRid >= Loongson-3B */ 2268c2ecf20Sopenharmony_ciextern u64 loongson_freqctrl[MAX_PACKAGES]; 2278c2ecf20Sopenharmony_ci#define LOONGSON_FREQCTRL(id) (*(volatile u32 *)(loongson_freqctrl[id])) 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci/* pcimap */ 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO0 0x0000003f 2328c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO0_SHIFT 0 2338c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO1 0x00000fc0 2348c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO1_SHIFT 6 2358c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO2 0x0003f000 2368c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_LO2_SHIFT 12 2378c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_PCIMAP_2 0x00040000 2388c2ecf20Sopenharmony_ci#define LOONGSON_PCIMAP_WIN(WIN, ADDR) \ 2398c2ecf20Sopenharmony_ci ((((ADDR)>>26) & LOONGSON_PCIMAP_PCIMAP_LO0) << ((WIN)*6)) 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci#endif /* __ASM_MACH_LOONGSON64_LOONGSON_H */ 242