octeon.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004-2008 Cavium Networks
  7. */
  8. #ifndef __ASM_OCTEON_OCTEON_H
  9. #define __ASM_OCTEON_OCTEON_H
  10. #include <asm/octeon/cvmx.h>
  11. #include <asm/bitfield.h>
  12. extern uint64_t octeon_bootmem_alloc_range_phys(uint64_t size,
  13. uint64_t alignment,
  14. uint64_t min_addr,
  15. uint64_t max_addr,
  16. int do_locking);
  17. extern void *octeon_bootmem_alloc(uint64_t size, uint64_t alignment,
  18. int do_locking);
  19. extern void *octeon_bootmem_alloc_range(uint64_t size, uint64_t alignment,
  20. uint64_t min_addr, uint64_t max_addr,
  21. int do_locking);
  22. extern void *octeon_bootmem_alloc_named(uint64_t size, uint64_t alignment,
  23. char *name);
  24. extern void *octeon_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
  25. uint64_t max_addr, uint64_t align,
  26. char *name);
  27. extern void *octeon_bootmem_alloc_named_address(uint64_t size, uint64_t address,
  28. char *name);
  29. extern int octeon_bootmem_free_named(char *name);
  30. extern void octeon_bootmem_lock(void);
  31. extern void octeon_bootmem_unlock(void);
  32. extern int octeon_is_simulation(void);
  33. extern int octeon_is_pci_host(void);
  34. extern int octeon_usb_is_ref_clk(void);
  35. extern uint64_t octeon_get_clock_rate(void);
  36. extern u64 octeon_get_io_clock_rate(void);
  37. extern const char *octeon_board_type_string(void);
  38. extern const char *octeon_get_pci_interrupts(void);
  39. extern int octeon_get_southbridge_interrupt(void);
  40. extern int octeon_get_boot_coremask(void);
  41. extern int octeon_get_boot_num_arguments(void);
  42. extern const char *octeon_get_boot_argument(int arg);
  43. extern void octeon_user_io_init(void);
  44. extern void octeon_init_cvmcount(void);
  45. extern void octeon_setup_delays(void);
  46. extern void octeon_io_clk_delay(unsigned long);
  47. #define OCTEON_ARGV_MAX_ARGS 64
  48. #define OCTEON_SERIAL_LEN 20
  49. struct octeon_boot_descriptor {
  50. #ifdef __BIG_ENDIAN_BITFIELD
  51. /* Start of block referenced by assembly code - do not change! */
  52. uint32_t desc_version;
  53. uint32_t desc_size;
  54. uint64_t stack_top;
  55. uint64_t heap_base;
  56. uint64_t heap_end;
  57. /* Only used by bootloader */
  58. uint64_t entry_point;
  59. uint64_t desc_vaddr;
  60. /* End of This block referenced by assembly code - do not change! */
  61. uint32_t exception_base_addr;
  62. uint32_t stack_size;
  63. uint32_t heap_size;
  64. /* Argc count for application. */
  65. uint32_t argc;
  66. uint32_t argv[OCTEON_ARGV_MAX_ARGS];
  67. #define BOOT_FLAG_INIT_CORE (1 << 0)
  68. #define OCTEON_BL_FLAG_DEBUG (1 << 1)
  69. #define OCTEON_BL_FLAG_NO_MAGIC (1 << 2)
  70. /* If set, use uart1 for console */
  71. #define OCTEON_BL_FLAG_CONSOLE_UART1 (1 << 3)
  72. /* If set, use PCI console */
  73. #define OCTEON_BL_FLAG_CONSOLE_PCI (1 << 4)
  74. /* Call exit on break on serial port */
  75. #define OCTEON_BL_FLAG_BREAK (1 << 5)
  76. uint32_t flags;
  77. uint32_t core_mask;
  78. /* DRAM size in megabyes. */
  79. uint32_t dram_size;
  80. /* physical address of free memory descriptor block. */
  81. uint32_t phy_mem_desc_addr;
  82. /* used to pass flags from app to debugger. */
  83. uint32_t debugger_flags_base_addr;
  84. /* CPU clock speed, in hz. */
  85. uint32_t eclock_hz;
  86. /* DRAM clock speed, in hz. */
  87. uint32_t dclock_hz;
  88. /* SPI4 clock in hz. */
  89. uint32_t spi_clock_hz;
  90. uint16_t board_type;
  91. uint8_t board_rev_major;
  92. uint8_t board_rev_minor;
  93. uint16_t chip_type;
  94. uint8_t chip_rev_major;
  95. uint8_t chip_rev_minor;
  96. char board_serial_number[OCTEON_SERIAL_LEN];
  97. uint8_t mac_addr_base[6];
  98. uint8_t mac_addr_count;
  99. uint64_t cvmx_desc_vaddr;
  100. #else
  101. uint32_t desc_size;
  102. uint32_t desc_version;
  103. uint64_t stack_top;
  104. uint64_t heap_base;
  105. uint64_t heap_end;
  106. /* Only used by bootloader */
  107. uint64_t entry_point;
  108. uint64_t desc_vaddr;
  109. /* End of This block referenced by assembly code - do not change! */
  110. uint32_t stack_size;
  111. uint32_t exception_base_addr;
  112. uint32_t argc;
  113. uint32_t heap_size;
  114. /*
  115. * Argc count for application.
  116. * Warning low bit scrambled in little-endian.
  117. */
  118. uint32_t argv[OCTEON_ARGV_MAX_ARGS];
  119. #define BOOT_FLAG_INIT_CORE (1 << 0)
  120. #define OCTEON_BL_FLAG_DEBUG (1 << 1)
  121. #define OCTEON_BL_FLAG_NO_MAGIC (1 << 2)
  122. /* If set, use uart1 for console */
  123. #define OCTEON_BL_FLAG_CONSOLE_UART1 (1 << 3)
  124. /* If set, use PCI console */
  125. #define OCTEON_BL_FLAG_CONSOLE_PCI (1 << 4)
  126. /* Call exit on break on serial port */
  127. #define OCTEON_BL_FLAG_BREAK (1 << 5)
  128. uint32_t core_mask;
  129. uint32_t flags;
  130. /* physical address of free memory descriptor block. */
  131. uint32_t phy_mem_desc_addr;
  132. /* DRAM size in megabyes. */
  133. uint32_t dram_size;
  134. /* CPU clock speed, in hz. */
  135. uint32_t eclock_hz;
  136. /* used to pass flags from app to debugger. */
  137. uint32_t debugger_flags_base_addr;
  138. /* SPI4 clock in hz. */
  139. uint32_t spi_clock_hz;
  140. /* DRAM clock speed, in hz. */
  141. uint32_t dclock_hz;
  142. uint8_t chip_rev_minor;
  143. uint8_t chip_rev_major;
  144. uint16_t chip_type;
  145. uint8_t board_rev_minor;
  146. uint8_t board_rev_major;
  147. uint16_t board_type;
  148. uint64_t unused1[4]; /* Not even filled in by bootloader. */
  149. uint64_t cvmx_desc_vaddr;
  150. #endif
  151. };
  152. union octeon_cvmemctl {
  153. uint64_t u64;
  154. struct {
  155. /* RO 1 = BIST fail, 0 = BIST pass */
  156. __BITFIELD_FIELD(uint64_t tlbbist:1,
  157. /* RO 1 = BIST fail, 0 = BIST pass */
  158. __BITFIELD_FIELD(uint64_t l1cbist:1,
  159. /* RO 1 = BIST fail, 0 = BIST pass */
  160. __BITFIELD_FIELD(uint64_t l1dbist:1,
  161. /* RO 1 = BIST fail, 0 = BIST pass */
  162. __BITFIELD_FIELD(uint64_t dcmbist:1,
  163. /* RO 1 = BIST fail, 0 = BIST pass */
  164. __BITFIELD_FIELD(uint64_t ptgbist:1,
  165. /* RO 1 = BIST fail, 0 = BIST pass */
  166. __BITFIELD_FIELD(uint64_t wbfbist:1,
  167. /* Reserved */
  168. __BITFIELD_FIELD(uint64_t reserved:17,
  169. /* OCTEON II - TLB replacement policy: 0 = bitmask LRU; 1 = NLU.
  170. * This field selects between the TLB replacement policies:
  171. * bitmask LRU or NLU. Bitmask LRU maintains a mask of
  172. * recently used TLB entries and avoids them as new entries
  173. * are allocated. NLU simply guarantees that the next
  174. * allocation is not the last used TLB entry. */
  175. __BITFIELD_FIELD(uint64_t tlbnlu:1,
  176. /* OCTEON II - Selects the bit in the counter used for
  177. * releasing a PAUSE. This counter trips every 2(8+PAUSETIME)
  178. * cycles. If not already released, the cnMIPS II core will
  179. * always release a given PAUSE instruction within
  180. * 2(8+PAUSETIME). If the counter trip happens to line up,
  181. * the cnMIPS II core may release the PAUSE instantly. */
  182. __BITFIELD_FIELD(uint64_t pausetime:3,
  183. /* OCTEON II - This field is an extension of
  184. * CvmMemCtl[DIDTTO] */
  185. __BITFIELD_FIELD(uint64_t didtto2:1,
  186. /* R/W If set, marked write-buffer entries time out
  187. * the same as other entries; if clear, marked
  188. * write-buffer entries use the maximum timeout. */
  189. __BITFIELD_FIELD(uint64_t dismarkwblongto:1,
  190. /* R/W If set, a merged store does not clear the
  191. * write-buffer entry timeout state. */
  192. __BITFIELD_FIELD(uint64_t dismrgclrwbto:1,
  193. /* R/W Two bits that are the MSBs of the resultant
  194. * CVMSEG LM word location for an IOBDMA. The other 8
  195. * bits come from the SCRADDR field of the IOBDMA. */
  196. __BITFIELD_FIELD(uint64_t iobdmascrmsb:2,
  197. /* R/W If set, SYNCWS and SYNCS only order marked
  198. * stores; if clear, SYNCWS and SYNCS only order
  199. * unmarked stores. SYNCWSMARKED has no effect when
  200. * DISSYNCWS is set. */
  201. __BITFIELD_FIELD(uint64_t syncwsmarked:1,
  202. /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as
  203. * SYNC. */
  204. __BITFIELD_FIELD(uint64_t dissyncws:1,
  205. /* R/W If set, no stall happens on write buffer
  206. * full. */
  207. __BITFIELD_FIELD(uint64_t diswbfst:1,
  208. /* R/W If set (and SX set), supervisor-level
  209. * loads/stores can use XKPHYS addresses with
  210. * VA<48>==0 */
  211. __BITFIELD_FIELD(uint64_t xkmemenas:1,
  212. /* R/W If set (and UX set), user-level loads/stores
  213. * can use XKPHYS addresses with VA<48>==0 */
  214. __BITFIELD_FIELD(uint64_t xkmemenau:1,
  215. /* R/W If set (and SX set), supervisor-level
  216. * loads/stores can use XKPHYS addresses with
  217. * VA<48>==1 */
  218. __BITFIELD_FIELD(uint64_t xkioenas:1,
  219. /* R/W If set (and UX set), user-level loads/stores
  220. * can use XKPHYS addresses with VA<48>==1 */
  221. __BITFIELD_FIELD(uint64_t xkioenau:1,
  222. /* R/W If set, all stores act as SYNCW (NOMERGE must
  223. * be set when this is set) RW, reset to 0. */
  224. __BITFIELD_FIELD(uint64_t allsyncw:1,
  225. /* R/W If set, no stores merge, and all stores reach
  226. * the coherent bus in order. */
  227. __BITFIELD_FIELD(uint64_t nomerge:1,
  228. /* R/W Selects the bit in the counter used for DID
  229. * time-outs 0 = 231, 1 = 230, 2 = 229, 3 =
  230. * 214. Actual time-out is between 1x and 2x this
  231. * interval. For example, with DIDTTO=3, expiration
  232. * interval is between 16K and 32K. */
  233. __BITFIELD_FIELD(uint64_t didtto:2,
  234. /* R/W If set, the (mem) CSR clock never turns off. */
  235. __BITFIELD_FIELD(uint64_t csrckalwys:1,
  236. /* R/W If set, mclk never turns off. */
  237. __BITFIELD_FIELD(uint64_t mclkalwys:1,
  238. /* R/W Selects the bit in the counter used for write
  239. * buffer flush time-outs (WBFLT+11) is the bit
  240. * position in an internal counter used to determine
  241. * expiration. The write buffer expires between 1x and
  242. * 2x this interval. For example, with WBFLT = 0, a
  243. * write buffer expires between 2K and 4K cycles after
  244. * the write buffer entry is allocated. */
  245. __BITFIELD_FIELD(uint64_t wbfltime:3,
  246. /* R/W If set, do not put Istream in the L2 cache. */
  247. __BITFIELD_FIELD(uint64_t istrnol2:1,
  248. /* R/W The write buffer threshold. */
  249. __BITFIELD_FIELD(uint64_t wbthresh:4,
  250. /* Reserved */
  251. __BITFIELD_FIELD(uint64_t reserved2:2,
  252. /* R/W If set, CVMSEG is available for loads/stores in
  253. * kernel/debug mode. */
  254. __BITFIELD_FIELD(uint64_t cvmsegenak:1,
  255. /* R/W If set, CVMSEG is available for loads/stores in
  256. * supervisor mode. */
  257. __BITFIELD_FIELD(uint64_t cvmsegenas:1,
  258. /* R/W If set, CVMSEG is available for loads/stores in
  259. * user mode. */
  260. __BITFIELD_FIELD(uint64_t cvmsegenau:1,
  261. /* R/W Size of local memory in cache blocks, 54 (6912
  262. * bytes) is max legal value. */
  263. __BITFIELD_FIELD(uint64_t lmemsz:6,
  264. ;)))))))))))))))))))))))))))))))))
  265. } s;
  266. };
  267. extern void octeon_check_cpu_bist(void);
  268. int octeon_prune_device_tree(void);
  269. extern const char __dtb_octeon_3xxx_begin;
  270. extern const char __dtb_octeon_68xx_begin;
  271. /**
  272. * Write a 32bit value to the Octeon NPI register space
  273. *
  274. * @address: Address to write to
  275. * @val: Value to write
  276. */
  277. static inline void octeon_npi_write32(uint64_t address, uint32_t val)
  278. {
  279. cvmx_write64_uint32(address ^ 4, val);
  280. cvmx_read64_uint32(address ^ 4);
  281. }
  282. #ifdef CONFIG_SMP
  283. void octeon_setup_smp(void);
  284. #else
  285. static inline void octeon_setup_smp(void) {}
  286. #endif
  287. struct irq_domain;
  288. struct device_node;
  289. struct irq_data;
  290. struct irq_chip;
  291. void octeon_ciu3_mbox_send(int cpu, unsigned int mbox);
  292. int octeon_irq_ciu3_xlat(struct irq_domain *d,
  293. struct device_node *node,
  294. const u32 *intspec,
  295. unsigned int intsize,
  296. unsigned long *out_hwirq,
  297. unsigned int *out_type);
  298. void octeon_irq_ciu3_enable(struct irq_data *data);
  299. void octeon_irq_ciu3_disable(struct irq_data *data);
  300. void octeon_irq_ciu3_ack(struct irq_data *data);
  301. void octeon_irq_ciu3_mask(struct irq_data *data);
  302. void octeon_irq_ciu3_mask_ack(struct irq_data *data);
  303. int octeon_irq_ciu3_mapx(struct irq_domain *d, unsigned int virq,
  304. irq_hw_number_t hw, struct irq_chip *chip);
  305. /* Octeon multiplier save/restore routines from octeon_switch.S */
  306. void octeon_mult_save(void);
  307. void octeon_mult_restore(void);
  308. void octeon_mult_save_end(void);
  309. void octeon_mult_restore_end(void);
  310. void octeon_mult_save3(void);
  311. void octeon_mult_save3_end(void);
  312. void octeon_mult_save2(void);
  313. void octeon_mult_save2_end(void);
  314. void octeon_mult_restore3(void);
  315. void octeon_mult_restore3_end(void);
  316. void octeon_mult_restore2(void);
  317. void octeon_mult_restore2_end(void);
  318. /**
  319. * Read a 32bit value from the Octeon NPI register space
  320. *
  321. * @address: Address to read
  322. * Returns The result
  323. */
  324. static inline uint32_t octeon_npi_read32(uint64_t address)
  325. {
  326. return cvmx_read64_uint32(address ^ 4);
  327. }
  328. extern struct cvmx_bootinfo *octeon_bootinfo;
  329. extern uint64_t octeon_bootloader_entry_addr;
  330. extern void (*octeon_irq_setup_secondary)(void);
  331. typedef void (*octeon_irq_ip4_handler_t)(void);
  332. void octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t);
  333. extern void octeon_fixup_irqs(void);
  334. extern struct semaphore octeon_bootbus_sem;
  335. struct irq_domain *octeon_irq_get_block_domain(int node, uint8_t block);
  336. #endif /* __ASM_OCTEON_OCTEON_H */