loongson.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2009 Lemote, Inc.
  4. * Author: Wu Zhangjin <[email protected]>
  5. */
  6. #ifndef __ASM_MACH_LOONGSON64_LOONGSON_H
  7. #define __ASM_MACH_LOONGSON64_LOONGSON_H
  8. #include <linux/io.h>
  9. #include <linux/init.h>
  10. #include <linux/irq.h>
  11. #include <boot_param.h>
  12. enum loongson_fw_interface {
  13. LOONGSON_LEFI,
  14. LOONGSON_DTB,
  15. };
  16. /* machine-specific boot configuration */
  17. struct loongson_system_configuration {
  18. enum loongson_fw_interface fw_interface;
  19. u32 nr_cpus;
  20. u32 nr_nodes;
  21. int cores_per_node;
  22. int cores_per_package;
  23. u16 boot_cpu_id;
  24. u16 reserved_cpus_mask;
  25. enum loongson_cpu_type cputype;
  26. enum loongson_bridge_type bridgetype;
  27. u64 restart_addr;
  28. u64 poweroff_addr;
  29. u64 suspend_addr;
  30. u64 vgabios_addr;
  31. u32 dma_mask_bits;
  32. u64 workarounds;
  33. void (*early_config)(void);
  34. };
  35. /* machine-specific reboot/halt operation */
  36. extern void mach_prepare_reboot(void);
  37. extern void mach_prepare_shutdown(void);
  38. /* environment arguments from bootloader */
  39. extern u32 cpu_clock_freq;
  40. extern u32 memsize, highmemsize;
  41. extern const struct plat_smp_ops loongson3_smp_ops;
  42. /* loongson-specific command line, env and memory initialization */
  43. extern void __init prom_dtb_init_env(void);
  44. extern void __init prom_lefi_init_env(void);
  45. extern void __init szmem(unsigned int node);
  46. extern void *loongson_fdt_blob;
  47. /* irq operation functions */
  48. extern void mach_irq_dispatch(unsigned int pending);
  49. extern int mach_i8259_irq(void);
  50. /* We need this in some places... */
  51. #define delay() ({ \
  52. int x; \
  53. for (x = 0; x < 100000; x++) \
  54. __asm__ __volatile__(""); \
  55. })
  56. #define LOONGSON_REG(x) \
  57. (*(volatile u32 *)((char *)CKSEG1ADDR(LOONGSON_REG_BASE) + (x)))
  58. #define LOONGSON3_REG8(base, x) \
  59. (*(volatile u8 *)((char *)TO_UNCAC(base) + (x)))
  60. #define LOONGSON3_REG32(base, x) \
  61. (*(volatile u32 *)((char *)TO_UNCAC(base) + (x)))
  62. #define LOONGSON_FLASH_BASE 0x1c000000
  63. #define LOONGSON_FLASH_SIZE 0x02000000 /* 32M */
  64. #define LOONGSON_FLASH_TOP (LOONGSON_FLASH_BASE+LOONGSON_FLASH_SIZE-1)
  65. #define LOONGSON_LIO0_BASE 0x1e000000
  66. #define LOONGSON_LIO0_SIZE 0x01C00000 /* 28M */
  67. #define LOONGSON_LIO0_TOP (LOONGSON_LIO0_BASE+LOONGSON_LIO0_SIZE-1)
  68. #define LOONGSON_BOOT_BASE 0x1fc00000
  69. #define LOONGSON_BOOT_SIZE 0x00100000 /* 1M */
  70. #define LOONGSON_BOOT_TOP (LOONGSON_BOOT_BASE+LOONGSON_BOOT_SIZE-1)
  71. #define LOONGSON_REG_BASE 0x1fe00000
  72. #define LOONGSON_REG_SIZE 0x00100000 /* 256Bytes + 256Bytes + ??? */
  73. #define LOONGSON_REG_TOP (LOONGSON_REG_BASE+LOONGSON_REG_SIZE-1)
  74. /* Loongson-3 specific registers */
  75. #define LOONGSON3_REG_BASE 0x3ff00000
  76. #define LOONGSON3_REG_SIZE 0x00100000 /* 256Bytes + 256Bytes + ??? */
  77. #define LOONGSON3_REG_TOP (LOONGSON3_REG_BASE+LOONGSON3_REG_SIZE-1)
  78. #define LOONGSON_LIO1_BASE 0x1ff00000
  79. #define LOONGSON_LIO1_SIZE 0x00100000 /* 1M */
  80. #define LOONGSON_LIO1_TOP (LOONGSON_LIO1_BASE+LOONGSON_LIO1_SIZE-1)
  81. #define LOONGSON_PCILO0_BASE 0x10000000
  82. #define LOONGSON_PCILO1_BASE 0x14000000
  83. #define LOONGSON_PCILO2_BASE 0x18000000
  84. #define LOONGSON_PCILO_BASE LOONGSON_PCILO0_BASE
  85. #define LOONGSON_PCILO_SIZE 0x0c000000 /* 64M * 3 */
  86. #define LOONGSON_PCILO_TOP (LOONGSON_PCILO0_BASE+LOONGSON_PCILO_SIZE-1)
  87. #define LOONGSON_PCICFG_BASE 0x1fe80000
  88. #define LOONGSON_PCICFG_SIZE 0x00000800 /* 2K */
  89. #define LOONGSON_PCICFG_TOP (LOONGSON_PCICFG_BASE+LOONGSON_PCICFG_SIZE-1)
  90. #define LOONGSON_PCIIO_BASE loongson_sysconf.pci_io_base
  91. #define LOONGSON_PCIIO_SIZE 0x00100000 /* 1M */
  92. #define LOONGSON_PCIIO_TOP (LOONGSON_PCIIO_BASE+LOONGSON_PCIIO_SIZE-1)
  93. /* Loongson Register Bases */
  94. #define LOONGSON_PCICONFIGBASE 0x00
  95. #define LOONGSON_REGBASE 0x100
  96. /* PCI Configuration Registers */
  97. #define LOONGSON_PCI_REG(x) LOONGSON_REG(LOONGSON_PCICONFIGBASE + (x))
  98. #define LOONGSON_PCIDID LOONGSON_PCI_REG(0x00)
  99. #define LOONGSON_PCICMD LOONGSON_PCI_REG(0x04)
  100. #define LOONGSON_PCICLASS LOONGSON_PCI_REG(0x08)
  101. #define LOONGSON_PCILTIMER LOONGSON_PCI_REG(0x0c)
  102. #define LOONGSON_PCIBASE0 LOONGSON_PCI_REG(0x10)
  103. #define LOONGSON_PCIBASE1 LOONGSON_PCI_REG(0x14)
  104. #define LOONGSON_PCIBASE2 LOONGSON_PCI_REG(0x18)
  105. #define LOONGSON_PCIBASE3 LOONGSON_PCI_REG(0x1c)
  106. #define LOONGSON_PCIBASE4 LOONGSON_PCI_REG(0x20)
  107. #define LOONGSON_PCIEXPRBASE LOONGSON_PCI_REG(0x30)
  108. #define LOONGSON_PCIINT LOONGSON_PCI_REG(0x3c)
  109. #define LOONGSON_PCI_ISR4C LOONGSON_PCI_REG(0x4c)
  110. #define LOONGSON_PCICMD_PERR_CLR 0x80000000
  111. #define LOONGSON_PCICMD_SERR_CLR 0x40000000
  112. #define LOONGSON_PCICMD_MABORT_CLR 0x20000000
  113. #define LOONGSON_PCICMD_MTABORT_CLR 0x10000000
  114. #define LOONGSON_PCICMD_TABORT_CLR 0x08000000
  115. #define LOONGSON_PCICMD_MPERR_CLR 0x01000000
  116. #define LOONGSON_PCICMD_PERRRESPEN 0x00000040
  117. #define LOONGSON_PCICMD_ASTEPEN 0x00000080
  118. #define LOONGSON_PCICMD_SERREN 0x00000100
  119. #define LOONGSON_PCILTIMER_BUSLATENCY 0x0000ff00
  120. #define LOONGSON_PCILTIMER_BUSLATENCY_SHIFT 8
  121. /* Loongson h/w Configuration */
  122. #define LOONGSON_GENCFG_OFFSET 0x4
  123. #define LOONGSON_GENCFG LOONGSON_REG(LOONGSON_REGBASE + LOONGSON_GENCFG_OFFSET)
  124. #define LOONGSON_GENCFG_DEBUGMODE 0x00000001
  125. #define LOONGSON_GENCFG_SNOOPEN 0x00000002
  126. #define LOONGSON_GENCFG_CPUSELFRESET 0x00000004
  127. #define LOONGSON_GENCFG_FORCE_IRQA 0x00000008
  128. #define LOONGSON_GENCFG_IRQA_ISOUT 0x00000010
  129. #define LOONGSON_GENCFG_IRQA_FROM_INT1 0x00000020
  130. #define LOONGSON_GENCFG_BYTESWAP 0x00000040
  131. #define LOONGSON_GENCFG_UNCACHED 0x00000080
  132. #define LOONGSON_GENCFG_PREFETCHEN 0x00000100
  133. #define LOONGSON_GENCFG_WBEHINDEN 0x00000200
  134. #define LOONGSON_GENCFG_CACHEALG 0x00000c00
  135. #define LOONGSON_GENCFG_CACHEALG_SHIFT 10
  136. #define LOONGSON_GENCFG_PCIQUEUE 0x00001000
  137. #define LOONGSON_GENCFG_CACHESTOP 0x00002000
  138. #define LOONGSON_GENCFG_MSTRBYTESWAP 0x00004000
  139. #define LOONGSON_GENCFG_BUSERREN 0x00008000
  140. #define LOONGSON_GENCFG_NORETRYTIMEOUT 0x00010000
  141. #define LOONGSON_GENCFG_SHORTCOPYTIMEOUT 0x00020000
  142. /* PCI address map control */
  143. #define LOONGSON_PCIMAP LOONGSON_REG(LOONGSON_REGBASE + 0x10)
  144. #define LOONGSON_PCIMEMBASECFG LOONGSON_REG(LOONGSON_REGBASE + 0x14)
  145. #define LOONGSON_PCIMAP_CFG LOONGSON_REG(LOONGSON_REGBASE + 0x18)
  146. /* GPIO Regs - r/w */
  147. #define LOONGSON_GPIODATA LOONGSON_REG(LOONGSON_REGBASE + 0x1c)
  148. #define LOONGSON_GPIOIE LOONGSON_REG(LOONGSON_REGBASE + 0x20)
  149. /* ICU Configuration Regs - r/w */
  150. #define LOONGSON_INTEDGE LOONGSON_REG(LOONGSON_REGBASE + 0x24)
  151. #define LOONGSON_INTSTEER LOONGSON_REG(LOONGSON_REGBASE + 0x28)
  152. #define LOONGSON_INTPOL LOONGSON_REG(LOONGSON_REGBASE + 0x2c)
  153. /* ICU Enable Regs - IntEn & IntISR are r/o. */
  154. #define LOONGSON_INTENSET LOONGSON_REG(LOONGSON_REGBASE + 0x30)
  155. #define LOONGSON_INTENCLR LOONGSON_REG(LOONGSON_REGBASE + 0x34)
  156. #define LOONGSON_INTEN LOONGSON_REG(LOONGSON_REGBASE + 0x38)
  157. #define LOONGSON_INTISR LOONGSON_REG(LOONGSON_REGBASE + 0x3c)
  158. /* ICU */
  159. #define LOONGSON_ICU_MBOXES 0x0000000f
  160. #define LOONGSON_ICU_MBOXES_SHIFT 0
  161. #define LOONGSON_ICU_DMARDY 0x00000010
  162. #define LOONGSON_ICU_DMAEMPTY 0x00000020
  163. #define LOONGSON_ICU_COPYRDY 0x00000040
  164. #define LOONGSON_ICU_COPYEMPTY 0x00000080
  165. #define LOONGSON_ICU_COPYERR 0x00000100
  166. #define LOONGSON_ICU_PCIIRQ 0x00000200
  167. #define LOONGSON_ICU_MASTERERR 0x00000400
  168. #define LOONGSON_ICU_SYSTEMERR 0x00000800
  169. #define LOONGSON_ICU_DRAMPERR 0x00001000
  170. #define LOONGSON_ICU_RETRYERR 0x00002000
  171. #define LOONGSON_ICU_GPIOS 0x01ff0000
  172. #define LOONGSON_ICU_GPIOS_SHIFT 16
  173. #define LOONGSON_ICU_GPINS 0x7e000000
  174. #define LOONGSON_ICU_GPINS_SHIFT 25
  175. #define LOONGSON_ICU_MBOX(N) (1<<(LOONGSON_ICU_MBOXES_SHIFT+(N)))
  176. #define LOONGSON_ICU_GPIO(N) (1<<(LOONGSON_ICU_GPIOS_SHIFT+(N)))
  177. #define LOONGSON_ICU_GPIN(N) (1<<(LOONGSON_ICU_GPINS_SHIFT+(N)))
  178. /* PCI prefetch window base & mask */
  179. #define LOONGSON_MEM_WIN_BASE_L LOONGSON_REG(LOONGSON_REGBASE + 0x40)
  180. #define LOONGSON_MEM_WIN_BASE_H LOONGSON_REG(LOONGSON_REGBASE + 0x44)
  181. #define LOONGSON_MEM_WIN_MASK_L LOONGSON_REG(LOONGSON_REGBASE + 0x48)
  182. #define LOONGSON_MEM_WIN_MASK_H LOONGSON_REG(LOONGSON_REGBASE + 0x4c)
  183. /* PCI_Hit*_Sel_* */
  184. #define LOONGSON_PCI_HIT0_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x50)
  185. #define LOONGSON_PCI_HIT0_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x54)
  186. #define LOONGSON_PCI_HIT1_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x58)
  187. #define LOONGSON_PCI_HIT1_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x5c)
  188. #define LOONGSON_PCI_HIT2_SEL_L LOONGSON_REG(LOONGSON_REGBASE + 0x60)
  189. #define LOONGSON_PCI_HIT2_SEL_H LOONGSON_REG(LOONGSON_REGBASE + 0x64)
  190. /* PXArb Config & Status */
  191. #define LOONGSON_PXARB_CFG LOONGSON_REG(LOONGSON_REGBASE + 0x68)
  192. #define LOONGSON_PXARB_STATUS LOONGSON_REG(LOONGSON_REGBASE + 0x6c)
  193. #define MAX_PACKAGES 4
  194. /* Chip Config registor of each physical cpu package, PRid >= Loongson-2F */
  195. extern u64 loongson_chipcfg[MAX_PACKAGES];
  196. #define LOONGSON_CHIPCFG(id) (*(volatile u32 *)(loongson_chipcfg[id]))
  197. /* Chip Temperature registor of each physical cpu package, PRid >= Loongson-3A */
  198. extern u64 loongson_chiptemp[MAX_PACKAGES];
  199. #define LOONGSON_CHIPTEMP(id) (*(volatile u32 *)(loongson_chiptemp[id]))
  200. /* Freq Control register of each physical cpu package, PRid >= Loongson-3B */
  201. extern u64 loongson_freqctrl[MAX_PACKAGES];
  202. #define LOONGSON_FREQCTRL(id) (*(volatile u32 *)(loongson_freqctrl[id]))
  203. /* pcimap */
  204. #define LOONGSON_PCIMAP_PCIMAP_LO0 0x0000003f
  205. #define LOONGSON_PCIMAP_PCIMAP_LO0_SHIFT 0
  206. #define LOONGSON_PCIMAP_PCIMAP_LO1 0x00000fc0
  207. #define LOONGSON_PCIMAP_PCIMAP_LO1_SHIFT 6
  208. #define LOONGSON_PCIMAP_PCIMAP_LO2 0x0003f000
  209. #define LOONGSON_PCIMAP_PCIMAP_LO2_SHIFT 12
  210. #define LOONGSON_PCIMAP_PCIMAP_2 0x00040000
  211. #define LOONGSON_PCIMAP_WIN(WIN, ADDR) \
  212. ((((ADDR)>>26) & LOONGSON_PCIMAP_PCIMAP_LO0) << ((WIN)*6))
  213. #endif /* __ASM_MACH_LOONGSON64_LOONGSON_H */