octeon.h 12 KB

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