blob: ba5df5023bae0d2049accffe2c8d493d7d767a0a [file] [log] [blame]
David Daney5b3b1682009-01-08 16:46:40 -08001/*
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
David Howellsa1ce3922012-10-02 18:01:25 +010011#include <asm/octeon/cvmx.h>
David Daney664f1ae2015-01-15 16:11:12 +030012#include <asm/bitfield.h>
David Daney5b3b1682009-01-08 16:46:40 -080013
14extern uint64_t octeon_bootmem_alloc_range_phys(uint64_t size,
15 uint64_t alignment,
16 uint64_t min_addr,
17 uint64_t max_addr,
18 int do_locking);
19extern void *octeon_bootmem_alloc(uint64_t size, uint64_t alignment,
20 int do_locking);
21extern void *octeon_bootmem_alloc_range(uint64_t size, uint64_t alignment,
22 uint64_t min_addr, uint64_t max_addr,
23 int do_locking);
24extern void *octeon_bootmem_alloc_named(uint64_t size, uint64_t alignment,
25 char *name);
26extern void *octeon_bootmem_alloc_named_range(uint64_t size, uint64_t min_addr,
27 uint64_t max_addr, uint64_t align,
28 char *name);
29extern void *octeon_bootmem_alloc_named_address(uint64_t size, uint64_t address,
30 char *name);
31extern int octeon_bootmem_free_named(char *name);
32extern void octeon_bootmem_lock(void);
33extern void octeon_bootmem_unlock(void);
34
35extern int octeon_is_simulation(void);
36extern int octeon_is_pci_host(void);
37extern int octeon_usb_is_ref_clk(void);
38extern uint64_t octeon_get_clock_rate(void);
David Daneye195aa32010-10-07 16:03:49 -070039extern u64 octeon_get_io_clock_rate(void);
David Daney5b3b1682009-01-08 16:46:40 -080040extern const char *octeon_board_type_string(void);
41extern const char *octeon_get_pci_interrupts(void);
42extern int octeon_get_southbridge_interrupt(void);
43extern int octeon_get_boot_coremask(void);
44extern int octeon_get_boot_num_arguments(void);
45extern const char *octeon_get_boot_argument(int arg);
46extern void octeon_hal_setup_reserved32(void);
47extern void octeon_user_io_init(void);
48struct octeon_cop2_state;
49extern unsigned long octeon_crypto_enable(struct octeon_cop2_state *state);
50extern void octeon_crypto_disable(struct octeon_cop2_state *state,
51 unsigned long flags);
Ralf Baechle69f3a7d2009-11-24 01:24:58 +000052extern asmlinkage void octeon_cop2_restore(struct octeon_cop2_state *task);
David Daney5b3b1682009-01-08 16:46:40 -080053
54extern void octeon_init_cvmcount(void);
David Daneyca148122010-06-01 13:18:15 -070055extern void octeon_setup_delays(void);
David Daney70a26a22012-08-21 11:45:05 -070056extern void octeon_io_clk_delay(unsigned long);
David Daney5b3b1682009-01-08 16:46:40 -080057
58#define OCTEON_ARGV_MAX_ARGS 64
59#define OCTOEN_SERIAL_LEN 20
60
61struct octeon_boot_descriptor {
David Daney664f1ae2015-01-15 16:11:12 +030062#ifdef __BIG_ENDIAN_BITFIELD
David Daney5b3b1682009-01-08 16:46:40 -080063 /* Start of block referenced by assembly code - do not change! */
64 uint32_t desc_version;
65 uint32_t desc_size;
66 uint64_t stack_top;
67 uint64_t heap_base;
68 uint64_t heap_end;
69 /* Only used by bootloader */
70 uint64_t entry_point;
71 uint64_t desc_vaddr;
72 /* End of This block referenced by assembly code - do not change! */
73 uint32_t exception_base_addr;
74 uint32_t stack_size;
75 uint32_t heap_size;
76 /* Argc count for application. */
77 uint32_t argc;
78 uint32_t argv[OCTEON_ARGV_MAX_ARGS];
79
Ralf Baechle70342282013-01-22 12:59:30 +010080#define BOOT_FLAG_INIT_CORE (1 << 0)
81#define OCTEON_BL_FLAG_DEBUG (1 << 1)
82#define OCTEON_BL_FLAG_NO_MAGIC (1 << 2)
David Daney5b3b1682009-01-08 16:46:40 -080083 /* If set, use uart1 for console */
Ralf Baechle70342282013-01-22 12:59:30 +010084#define OCTEON_BL_FLAG_CONSOLE_UART1 (1 << 3)
David Daney5b3b1682009-01-08 16:46:40 -080085 /* If set, use PCI console */
Ralf Baechle70342282013-01-22 12:59:30 +010086#define OCTEON_BL_FLAG_CONSOLE_PCI (1 << 4)
David Daney5b3b1682009-01-08 16:46:40 -080087 /* Call exit on break on serial port */
Ralf Baechle70342282013-01-22 12:59:30 +010088#define OCTEON_BL_FLAG_BREAK (1 << 5)
David Daney5b3b1682009-01-08 16:46:40 -080089
90 uint32_t flags;
91 uint32_t core_mask;
92 /* DRAM size in megabyes. */
93 uint32_t dram_size;
94 /* physical address of free memory descriptor block. */
95 uint32_t phy_mem_desc_addr;
96 /* used to pass flags from app to debugger. */
97 uint32_t debugger_flags_base_addr;
98 /* CPU clock speed, in hz. */
99 uint32_t eclock_hz;
100 /* DRAM clock speed, in hz. */
101 uint32_t dclock_hz;
102 /* SPI4 clock in hz. */
103 uint32_t spi_clock_hz;
104 uint16_t board_type;
105 uint8_t board_rev_major;
106 uint8_t board_rev_minor;
107 uint16_t chip_type;
108 uint8_t chip_rev_major;
109 uint8_t chip_rev_minor;
110 char board_serial_number[OCTOEN_SERIAL_LEN];
111 uint8_t mac_addr_base[6];
112 uint8_t mac_addr_count;
113 uint64_t cvmx_desc_vaddr;
David Daney664f1ae2015-01-15 16:11:12 +0300114#else
115 uint32_t desc_size;
116 uint32_t desc_version;
117 uint64_t stack_top;
118 uint64_t heap_base;
119 uint64_t heap_end;
120 /* Only used by bootloader */
121 uint64_t entry_point;
122 uint64_t desc_vaddr;
123 /* End of This block referenced by assembly code - do not change! */
124 uint32_t stack_size;
125 uint32_t exception_base_addr;
126 uint32_t argc;
127 uint32_t heap_size;
128 /*
129 * Argc count for application.
130 * Warning low bit scrambled in little-endian.
131 */
132 uint32_t argv[OCTEON_ARGV_MAX_ARGS];
133
134#define BOOT_FLAG_INIT_CORE (1 << 0)
135#define OCTEON_BL_FLAG_DEBUG (1 << 1)
136#define OCTEON_BL_FLAG_NO_MAGIC (1 << 2)
137 /* If set, use uart1 for console */
138#define OCTEON_BL_FLAG_CONSOLE_UART1 (1 << 3)
139 /* If set, use PCI console */
140#define OCTEON_BL_FLAG_CONSOLE_PCI (1 << 4)
141 /* Call exit on break on serial port */
142#define OCTEON_BL_FLAG_BREAK (1 << 5)
143
144 uint32_t core_mask;
145 uint32_t flags;
146 /* physical address of free memory descriptor block. */
147 uint32_t phy_mem_desc_addr;
148 /* DRAM size in megabyes. */
149 uint32_t dram_size;
150 /* CPU clock speed, in hz. */
151 uint32_t eclock_hz;
152 /* used to pass flags from app to debugger. */
153 uint32_t debugger_flags_base_addr;
154 /* SPI4 clock in hz. */
155 uint32_t spi_clock_hz;
156 /* DRAM clock speed, in hz. */
157 uint32_t dclock_hz;
158 uint8_t chip_rev_minor;
159 uint8_t chip_rev_major;
160 uint16_t chip_type;
161 uint8_t board_rev_minor;
162 uint8_t board_rev_major;
163 uint16_t board_type;
164
165 uint64_t unused1[4]; /* Not even filled in by bootloader. */
166
167 uint64_t cvmx_desc_vaddr;
168#endif
David Daney5b3b1682009-01-08 16:46:40 -0800169};
170
171union octeon_cvmemctl {
172 uint64_t u64;
173 struct {
174 /* RO 1 = BIST fail, 0 = BIST pass */
David Daney664f1ae2015-01-15 16:11:12 +0300175 __BITFIELD_FIELD(uint64_t tlbbist:1,
David Daney5b3b1682009-01-08 16:46:40 -0800176 /* RO 1 = BIST fail, 0 = BIST pass */
David Daney664f1ae2015-01-15 16:11:12 +0300177 __BITFIELD_FIELD(uint64_t l1cbist:1,
David Daney5b3b1682009-01-08 16:46:40 -0800178 /* RO 1 = BIST fail, 0 = BIST pass */
David Daney664f1ae2015-01-15 16:11:12 +0300179 __BITFIELD_FIELD(uint64_t l1dbist:1,
David Daney5b3b1682009-01-08 16:46:40 -0800180 /* RO 1 = BIST fail, 0 = BIST pass */
David Daney664f1ae2015-01-15 16:11:12 +0300181 __BITFIELD_FIELD(uint64_t dcmbist:1,
David Daney5b3b1682009-01-08 16:46:40 -0800182 /* RO 1 = BIST fail, 0 = BIST pass */
David Daney664f1ae2015-01-15 16:11:12 +0300183 __BITFIELD_FIELD(uint64_t ptgbist:1,
David Daney5b3b1682009-01-08 16:46:40 -0800184 /* RO 1 = BIST fail, 0 = BIST pass */
David Daney664f1ae2015-01-15 16:11:12 +0300185 __BITFIELD_FIELD(uint64_t wbfbist:1,
David Daney5b3b1682009-01-08 16:46:40 -0800186 /* Reserved */
David Daney664f1ae2015-01-15 16:11:12 +0300187 __BITFIELD_FIELD(uint64_t reserved:17,
188 /* OCTEON II - TLB replacement policy: 0 = bitmask LRU; 1 = NLU.
189 * This field selects between the TLB replacement policies:
190 * bitmask LRU or NLU. Bitmask LRU maintains a mask of
191 * recently used TLB entries and avoids them as new entries
192 * are allocated. NLU simply guarantees that the next
193 * allocation is not the last used TLB entry. */
194 __BITFIELD_FIELD(uint64_t tlbnlu:1,
195 /* OCTEON II - Selects the bit in the counter used for
196 * releasing a PAUSE. This counter trips every 2(8+PAUSETIME)
197 * cycles. If not already released, the cnMIPS II core will
198 * always release a given PAUSE instruction within
199 * 2(8+PAUSETIME). If the counter trip happens to line up,
200 * the cnMIPS II core may release the PAUSE instantly. */
201 __BITFIELD_FIELD(uint64_t pausetime:3,
202 /* OCTEON II - This field is an extension of
203 * CvmMemCtl[DIDTTO] */
204 __BITFIELD_FIELD(uint64_t didtto2:1,
David Daney5b3b1682009-01-08 16:46:40 -0800205 /* R/W If set, marked write-buffer entries time out
206 * the same as as other entries; if clear, marked
207 * write-buffer entries use the maximum timeout. */
David Daney664f1ae2015-01-15 16:11:12 +0300208 __BITFIELD_FIELD(uint64_t dismarkwblongto:1,
David Daney5b3b1682009-01-08 16:46:40 -0800209 /* R/W If set, a merged store does not clear the
210 * write-buffer entry timeout state. */
David Daney664f1ae2015-01-15 16:11:12 +0300211 __BITFIELD_FIELD(uint64_t dismrgclrwbto:1,
David Daney5b3b1682009-01-08 16:46:40 -0800212 /* R/W Two bits that are the MSBs of the resultant
213 * CVMSEG LM word location for an IOBDMA. The other 8
214 * bits come from the SCRADDR field of the IOBDMA. */
David Daney664f1ae2015-01-15 16:11:12 +0300215 __BITFIELD_FIELD(uint64_t iobdmascrmsb:2,
David Daney5b3b1682009-01-08 16:46:40 -0800216 /* R/W If set, SYNCWS and SYNCS only order marked
217 * stores; if clear, SYNCWS and SYNCS only order
218 * unmarked stores. SYNCWSMARKED has no effect when
219 * DISSYNCWS is set. */
David Daney664f1ae2015-01-15 16:11:12 +0300220 __BITFIELD_FIELD(uint64_t syncwsmarked:1,
David Daney5b3b1682009-01-08 16:46:40 -0800221 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as
222 * SYNC. */
David Daney664f1ae2015-01-15 16:11:12 +0300223 __BITFIELD_FIELD(uint64_t dissyncws:1,
David Daney5b3b1682009-01-08 16:46:40 -0800224 /* R/W If set, no stall happens on write buffer
225 * full. */
David Daney664f1ae2015-01-15 16:11:12 +0300226 __BITFIELD_FIELD(uint64_t diswbfst:1,
David Daney5b3b1682009-01-08 16:46:40 -0800227 /* R/W If set (and SX set), supervisor-level
228 * loads/stores can use XKPHYS addresses with
229 * VA<48>==0 */
David Daney664f1ae2015-01-15 16:11:12 +0300230 __BITFIELD_FIELD(uint64_t xkmemenas:1,
David Daney5b3b1682009-01-08 16:46:40 -0800231 /* R/W If set (and UX set), user-level loads/stores
232 * can use XKPHYS addresses with VA<48>==0 */
David Daney664f1ae2015-01-15 16:11:12 +0300233 __BITFIELD_FIELD(uint64_t xkmemenau:1,
David Daney5b3b1682009-01-08 16:46:40 -0800234 /* R/W If set (and SX set), supervisor-level
235 * loads/stores can use XKPHYS addresses with
236 * VA<48>==1 */
David Daney664f1ae2015-01-15 16:11:12 +0300237 __BITFIELD_FIELD(uint64_t xkioenas:1,
David Daney5b3b1682009-01-08 16:46:40 -0800238 /* R/W If set (and UX set), user-level loads/stores
239 * can use XKPHYS addresses with VA<48>==1 */
David Daney664f1ae2015-01-15 16:11:12 +0300240 __BITFIELD_FIELD(uint64_t xkioenau:1,
David Daney5b3b1682009-01-08 16:46:40 -0800241 /* R/W If set, all stores act as SYNCW (NOMERGE must
242 * be set when this is set) RW, reset to 0. */
David Daney664f1ae2015-01-15 16:11:12 +0300243 __BITFIELD_FIELD(uint64_t allsyncw:1,
David Daney5b3b1682009-01-08 16:46:40 -0800244 /* R/W If set, no stores merge, and all stores reach
245 * the coherent bus in order. */
David Daney664f1ae2015-01-15 16:11:12 +0300246 __BITFIELD_FIELD(uint64_t nomerge:1,
David Daney5b3b1682009-01-08 16:46:40 -0800247 /* R/W Selects the bit in the counter used for DID
248 * time-outs 0 = 231, 1 = 230, 2 = 229, 3 =
249 * 214. Actual time-out is between 1x and 2x this
250 * interval. For example, with DIDTTO=3, expiration
251 * interval is between 16K and 32K. */
David Daney664f1ae2015-01-15 16:11:12 +0300252 __BITFIELD_FIELD(uint64_t didtto:2,
David Daney5b3b1682009-01-08 16:46:40 -0800253 /* R/W If set, the (mem) CSR clock never turns off. */
David Daney664f1ae2015-01-15 16:11:12 +0300254 __BITFIELD_FIELD(uint64_t csrckalwys:1,
David Daney5b3b1682009-01-08 16:46:40 -0800255 /* R/W If set, mclk never turns off. */
David Daney664f1ae2015-01-15 16:11:12 +0300256 __BITFIELD_FIELD(uint64_t mclkalwys:1,
David Daney5b3b1682009-01-08 16:46:40 -0800257 /* R/W Selects the bit in the counter used for write
258 * buffer flush time-outs (WBFLT+11) is the bit
259 * position in an internal counter used to determine
260 * expiration. The write buffer expires between 1x and
261 * 2x this interval. For example, with WBFLT = 0, a
262 * write buffer expires between 2K and 4K cycles after
263 * the write buffer entry is allocated. */
David Daney664f1ae2015-01-15 16:11:12 +0300264 __BITFIELD_FIELD(uint64_t wbfltime:3,
David Daney5b3b1682009-01-08 16:46:40 -0800265 /* R/W If set, do not put Istream in the L2 cache. */
David Daney664f1ae2015-01-15 16:11:12 +0300266 __BITFIELD_FIELD(uint64_t istrnol2:1,
David Daney5b3b1682009-01-08 16:46:40 -0800267 /* R/W The write buffer threshold. */
David Daney664f1ae2015-01-15 16:11:12 +0300268 __BITFIELD_FIELD(uint64_t wbthresh:4,
David Daney5b3b1682009-01-08 16:46:40 -0800269 /* Reserved */
David Daney664f1ae2015-01-15 16:11:12 +0300270 __BITFIELD_FIELD(uint64_t reserved2:2,
David Daney5b3b1682009-01-08 16:46:40 -0800271 /* R/W If set, CVMSEG is available for loads/stores in
272 * kernel/debug mode. */
David Daney664f1ae2015-01-15 16:11:12 +0300273 __BITFIELD_FIELD(uint64_t cvmsegenak:1,
David Daney5b3b1682009-01-08 16:46:40 -0800274 /* R/W If set, CVMSEG is available for loads/stores in
275 * supervisor mode. */
David Daney664f1ae2015-01-15 16:11:12 +0300276 __BITFIELD_FIELD(uint64_t cvmsegenas:1,
David Daney5b3b1682009-01-08 16:46:40 -0800277 /* R/W If set, CVMSEG is available for loads/stores in
278 * user mode. */
David Daney664f1ae2015-01-15 16:11:12 +0300279 __BITFIELD_FIELD(uint64_t cvmsegenau:1,
David Daney5b3b1682009-01-08 16:46:40 -0800280 /* R/W Size of local memory in cache blocks, 54 (6912
281 * bytes) is max legal value. */
David Daney664f1ae2015-01-15 16:11:12 +0300282 __BITFIELD_FIELD(uint64_t lmemsz:6,
283 ;)))))))))))))))))))))))))))))))))
David Daney5b3b1682009-01-08 16:46:40 -0800284 } s;
285};
286
David Daney5b3b1682009-01-08 16:46:40 -0800287extern void octeon_write_lcd(const char *s);
288extern void octeon_check_cpu_bist(void);
David Daney5b3b1682009-01-08 16:46:40 -0800289extern int octeon_get_boot_uart(void);
290
291struct uart_port;
292extern unsigned int octeon_serial_in(struct uart_port *, int);
293extern void octeon_serial_out(struct uart_port *, int, int);
294
295/**
296 * Write a 32bit value to the Octeon NPI register space
297 *
298 * @address: Address to write to
299 * @val: Value to write
300 */
301static inline void octeon_npi_write32(uint64_t address, uint32_t val)
302{
303 cvmx_write64_uint32(address ^ 4, val);
304 cvmx_read64_uint32(address ^ 4);
305}
306
David Daneyac655fb2015-01-15 16:11:05 +0300307/* Octeon multiplier save/restore routines from octeon_switch.S */
308void octeon_mult_save(void);
309void octeon_mult_restore(void);
310void octeon_mult_save_end(void);
311void octeon_mult_restore_end(void);
312void octeon_mult_save3(void);
313void octeon_mult_save3_end(void);
314void octeon_mult_save2(void);
315void octeon_mult_save2_end(void);
316void octeon_mult_restore3(void);
317void octeon_mult_restore3_end(void);
318void octeon_mult_restore2(void);
319void octeon_mult_restore2_end(void);
David Daney5b3b1682009-01-08 16:46:40 -0800320
321/**
322 * Read a 32bit value from the Octeon NPI register space
323 *
324 * @address: Address to read
325 * Returns The result
326 */
327static inline uint32_t octeon_npi_read32(uint64_t address)
328{
329 return cvmx_read64_uint32(address ^ 4);
330}
331
David Daneye8635b42009-04-23 17:44:38 -0700332extern struct cvmx_bootinfo *octeon_bootinfo;
333
David Daneybabba4f2010-07-23 10:57:51 -0700334extern uint64_t octeon_bootloader_entry_addr;
335
David Daney0c326382011-03-25 12:38:51 -0700336extern void (*octeon_irq_setup_secondary)(void);
337
David Daney88fd8582012-04-04 15:34:41 -0700338typedef void (*octeon_irq_ip4_handler_t)(void);
339void octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t);
340
Ralf Baechle17efb592013-09-03 18:19:28 +0200341extern void octeon_fixup_irqs(void);
342
David Daney5b3b1682009-01-08 16:46:40 -0800343#endif /* __ASM_OCTEON_OCTEON_H */