1af866496SDavid Daney /***********************license start***************
2af866496SDavid Daney  * Author: Cavium Networks
3af866496SDavid Daney  *
4af866496SDavid Daney  * Contact: support@caviumnetworks.com
5af866496SDavid Daney  * This file is part of the OCTEON SDK
6af866496SDavid Daney  *
7af866496SDavid Daney  * Copyright (c) 2003-2009 Cavium Networks
8af866496SDavid Daney  *
9af866496SDavid Daney  * This file is free software; you can redistribute it and/or modify
10af866496SDavid Daney  * it under the terms of the GNU General Public License, Version 2, as
11af866496SDavid Daney  * published by the Free Software Foundation.
12af866496SDavid Daney  *
13af866496SDavid Daney  * This file is distributed in the hope that it will be useful, but
14af866496SDavid Daney  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15af866496SDavid Daney  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16af866496SDavid Daney  * NONINFRINGEMENT.  See the GNU General Public License for more
17af866496SDavid Daney  * details.
18af866496SDavid Daney  *
19af866496SDavid Daney  * You should have received a copy of the GNU General Public License
20af866496SDavid Daney  * along with this file; if not, write to the Free Software
21af866496SDavid Daney  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22af866496SDavid Daney  * or visit http://www.gnu.org/licenses/.
23af866496SDavid Daney  *
24af866496SDavid Daney  * This file may also be available under a different license from Cavium.
25af866496SDavid Daney  * Contact Cavium Networks for more information
26af866496SDavid Daney  ***********************license end**************************************/
27af866496SDavid Daney 
28af866496SDavid Daney /**
29af866496SDavid Daney  * Typedefs and defines for working with Octeon physical addresses.
30af866496SDavid Daney  *
31af866496SDavid Daney  */
32af866496SDavid Daney #ifndef __CVMX_ADDRESS_H__
33af866496SDavid Daney #define __CVMX_ADDRESS_H__
34af866496SDavid Daney 
35af866496SDavid Daney #if 0
36af866496SDavid Daney typedef enum {
37af866496SDavid Daney 	CVMX_MIPS_SPACE_XKSEG = 3LL,
38af866496SDavid Daney 	CVMX_MIPS_SPACE_XKPHYS = 2LL,
39af866496SDavid Daney 	CVMX_MIPS_SPACE_XSSEG = 1LL,
40af866496SDavid Daney 	CVMX_MIPS_SPACE_XUSEG = 0LL
41af866496SDavid Daney } cvmx_mips_space_t;
42af866496SDavid Daney #endif
43af866496SDavid Daney 
44af866496SDavid Daney typedef enum {
45af866496SDavid Daney 	CVMX_MIPS_XKSEG_SPACE_KSEG0 = 0LL,
46af866496SDavid Daney 	CVMX_MIPS_XKSEG_SPACE_KSEG1 = 1LL,
47af866496SDavid Daney 	CVMX_MIPS_XKSEG_SPACE_SSEG = 2LL,
48af866496SDavid Daney 	CVMX_MIPS_XKSEG_SPACE_KSEG3 = 3LL
49af866496SDavid Daney } cvmx_mips_xkseg_space_t;
50af866496SDavid Daney 
51af866496SDavid Daney /* decodes <14:13> of a kseg3 window address */
52af866496SDavid Daney typedef enum {
53af866496SDavid Daney 	CVMX_ADD_WIN_SCR = 0L,
54af866496SDavid Daney 	/* see cvmx_add_win_dma_dec_t for further decode */
55af866496SDavid Daney 	CVMX_ADD_WIN_DMA = 1L,
56af866496SDavid Daney 	CVMX_ADD_WIN_UNUSED = 2L,
57af866496SDavid Daney 	CVMX_ADD_WIN_UNUSED2 = 3L
58af866496SDavid Daney } cvmx_add_win_dec_t;
59af866496SDavid Daney 
60af866496SDavid Daney /* decode within DMA space */
61af866496SDavid Daney typedef enum {
62af866496SDavid Daney 	/*
63af866496SDavid Daney 	 * Add store data to the write buffer entry, allocating it if
64af866496SDavid Daney 	 * necessary.
65af866496SDavid Daney 	 */
66af866496SDavid Daney 	CVMX_ADD_WIN_DMA_ADD = 0L,
67af866496SDavid Daney 	/* send out the write buffer entry to DRAM */
68af866496SDavid Daney 	CVMX_ADD_WIN_DMA_SENDMEM = 1L,
69af866496SDavid Daney 	/* store data must be normal DRAM memory space address in this case */
70af866496SDavid Daney 	/* send out the write buffer entry as an IOBDMA command */
71af866496SDavid Daney 	CVMX_ADD_WIN_DMA_SENDDMA = 2L,
72af866496SDavid Daney 	/* see CVMX_ADD_WIN_DMA_SEND_DEC for data contents */
73af866496SDavid Daney 	/* send out the write buffer entry as an IO write */
74af866496SDavid Daney 	CVMX_ADD_WIN_DMA_SENDIO = 3L,
75af866496SDavid Daney 	/* store data must be normal IO space address in this case */
76af866496SDavid Daney 	/* send out a single-tick command on the NCB bus */
77af866496SDavid Daney 	CVMX_ADD_WIN_DMA_SENDSINGLE = 4L,
78af866496SDavid Daney 	/* no write buffer data needed/used */
79af866496SDavid Daney } cvmx_add_win_dma_dec_t;
80af866496SDavid Daney 
81af866496SDavid Daney /*
82af866496SDavid Daney  *   Physical Address Decode
83af866496SDavid Daney  *
84af866496SDavid Daney  * Octeon-I HW never interprets this X (<39:36> reserved
85af866496SDavid Daney  * for future expansion), software should set to 0.
86af866496SDavid Daney  *
87af866496SDavid Daney  *  - 0x0 XXX0 0000 0000 to      DRAM         Cached
88af866496SDavid Daney  *  - 0x0 XXX0 0FFF FFFF
89af866496SDavid Daney  *
90af866496SDavid Daney  *  - 0x0 XXX0 1000 0000 to      Boot Bus     Uncached  (Converted to 0x1 00X0 1000 0000
91af866496SDavid Daney  *  - 0x0 XXX0 1FFF FFFF         + EJTAG                           to 0x1 00X0 1FFF FFFF)
92af866496SDavid Daney  *
93af866496SDavid Daney  *  - 0x0 XXX0 2000 0000 to      DRAM         Cached
94af866496SDavid Daney  *  - 0x0 XXXF FFFF FFFF
95af866496SDavid Daney  *
96af866496SDavid Daney  *  - 0x1 00X0 0000 0000 to      Boot Bus     Uncached
97af866496SDavid Daney  *  - 0x1 00XF FFFF FFFF
98af866496SDavid Daney  *
99af866496SDavid Daney  *  - 0x1 01X0 0000 0000 to      Other NCB    Uncached
100af866496SDavid Daney  *  - 0x1 FFXF FFFF FFFF         devices
101af866496SDavid Daney  *
102af866496SDavid Daney  * Decode of all Octeon addresses
103af866496SDavid Daney  */
104af866496SDavid Daney typedef union {
105af866496SDavid Daney 
106af866496SDavid Daney 	uint64_t u64;
107af866496SDavid Daney 	/* mapped or unmapped virtual address */
108af866496SDavid Daney 	struct {
109af866496SDavid Daney 		uint64_t R:2;
110af866496SDavid Daney 		uint64_t offset:62;
111af866496SDavid Daney 	} sva;
112af866496SDavid Daney 
113af866496SDavid Daney 	/* mapped USEG virtual addresses (typically) */
114af866496SDavid Daney 	struct {
115af866496SDavid Daney 		uint64_t zeroes:33;
116af866496SDavid Daney 		uint64_t offset:31;
117af866496SDavid Daney 	} suseg;
118af866496SDavid Daney 
119af866496SDavid Daney 	/* mapped or unmapped virtual address */
120af866496SDavid Daney 	struct {
121af866496SDavid Daney 		uint64_t ones:33;
122af866496SDavid Daney 		uint64_t sp:2;
123af866496SDavid Daney 		uint64_t offset:29;
124af866496SDavid Daney 	} sxkseg;
125af866496SDavid Daney 
126af866496SDavid Daney 	/*
127af866496SDavid Daney 	 * physical address accessed through xkphys unmapped virtual
128af866496SDavid Daney 	 * address.
129af866496SDavid Daney 	 */
130af866496SDavid Daney 	struct {
131af866496SDavid Daney 		uint64_t R:2;	/* CVMX_MIPS_SPACE_XKPHYS in this case */
132af866496SDavid Daney 		uint64_t cca:3;	/* ignored by octeon */
133af866496SDavid Daney 		uint64_t mbz:10;
134af866496SDavid Daney 		uint64_t pa:49;	/* physical address */
135af866496SDavid Daney 	} sxkphys;
136af866496SDavid Daney 
137af866496SDavid Daney 	/* physical address */
138af866496SDavid Daney 	struct {
139af866496SDavid Daney 		uint64_t mbz:15;
140af866496SDavid Daney 		/* if set, the address is uncached and resides on MCB bus */
141af866496SDavid Daney 		uint64_t is_io:1;
142af866496SDavid Daney 		/*
143af866496SDavid Daney 		 * the hardware ignores this field when is_io==0, else
144af866496SDavid Daney 		 * device ID.
145af866496SDavid Daney 		 */
146af866496SDavid Daney 		uint64_t did:8;
147af866496SDavid Daney 		/* the hardware ignores <39:36> in Octeon I */
148af866496SDavid Daney 		uint64_t unaddr:4;
149af866496SDavid Daney 		uint64_t offset:36;
150af866496SDavid Daney 	} sphys;
151af866496SDavid Daney 
152af866496SDavid Daney 	/* physical mem address */
153af866496SDavid Daney 	struct {
154af866496SDavid Daney 		/* techically, <47:40> are dont-cares */
155af866496SDavid Daney 		uint64_t zeroes:24;
156af866496SDavid Daney 		/* the hardware ignores <39:36> in Octeon I */
157af866496SDavid Daney 		uint64_t unaddr:4;
158af866496SDavid Daney 		uint64_t offset:36;
159af866496SDavid Daney 	} smem;
160af866496SDavid Daney 
161af866496SDavid Daney 	/* physical IO address */
162af866496SDavid Daney 	struct {
163af866496SDavid Daney 		uint64_t mem_region:2;
164af866496SDavid Daney 		uint64_t mbz:13;
165af866496SDavid Daney 		/* 1 in this case */
166af866496SDavid Daney 		uint64_t is_io:1;
167af866496SDavid Daney 		/*
168af866496SDavid Daney 		 * The hardware ignores this field when is_io==0, else
169af866496SDavid Daney 		 * device ID.
170af866496SDavid Daney 		 */
171af866496SDavid Daney 		uint64_t did:8;
172af866496SDavid Daney 		/* the hardware ignores <39:36> in Octeon I */
173af866496SDavid Daney 		uint64_t unaddr:4;
174af866496SDavid Daney 		uint64_t offset:36;
175af866496SDavid Daney 	} sio;
176af866496SDavid Daney 
177af866496SDavid Daney 	/*
178af866496SDavid Daney 	 * Scratchpad virtual address - accessed through a window at
179af866496SDavid Daney 	 * the end of kseg3
180af866496SDavid Daney 	 */
181af866496SDavid Daney 	struct {
182af866496SDavid Daney 		uint64_t ones:49;
183af866496SDavid Daney 		/* CVMX_ADD_WIN_SCR (0) in this case */
184af866496SDavid Daney 		cvmx_add_win_dec_t csrdec:2;
185af866496SDavid Daney 		uint64_t addr:13;
186af866496SDavid Daney 	} sscr;
187af866496SDavid Daney 
188af866496SDavid Daney 	/* there should only be stores to IOBDMA space, no loads */
189af866496SDavid Daney 	/*
190af866496SDavid Daney 	 * IOBDMA virtual address - accessed through a window at the
191af866496SDavid Daney 	 * end of kseg3
192af866496SDavid Daney 	 */
193af866496SDavid Daney 	struct {
194af866496SDavid Daney 		uint64_t ones:49;
195af866496SDavid Daney 		uint64_t csrdec:2;	/* CVMX_ADD_WIN_DMA (1) in this case */
196af866496SDavid Daney 		uint64_t unused2:3;
197af866496SDavid Daney 		uint64_t type:3;
198af866496SDavid Daney 		uint64_t addr:7;
199af866496SDavid Daney 	} sdma;
200af866496SDavid Daney 
201af866496SDavid Daney 	struct {
202af866496SDavid Daney 		uint64_t didspace:24;
203af866496SDavid Daney 		uint64_t unused:40;
204af866496SDavid Daney 	} sfilldidspace;
205af866496SDavid Daney 
206af866496SDavid Daney } cvmx_addr_t;
207af866496SDavid Daney 
208af866496SDavid Daney /* These macros for used by 32 bit applications */
209af866496SDavid Daney 
210af866496SDavid Daney #define CVMX_MIPS32_SPACE_KSEG0 1l
211af866496SDavid Daney #define CVMX_ADD_SEG32(segment, add) \
212af866496SDavid Daney 	(((int32_t)segment << 31) | (int32_t)(add))
213af866496SDavid Daney 
214af866496SDavid Daney /*
215af866496SDavid Daney  * Currently all IOs are performed using XKPHYS addressing. Linux uses
216af866496SDavid Daney  * the CvmMemCtl register to enable XKPHYS addressing to IO space from
217af866496SDavid Daney  * user mode.  Future OSes may need to change the upper bits of IO
218af866496SDavid Daney  * addresses. The following define controls the upper two bits for all
219af866496SDavid Daney  * IO addresses generated by the simple executive library.
220af866496SDavid Daney  */
221af866496SDavid Daney #define CVMX_IO_SEG CVMX_MIPS_SPACE_XKPHYS
222af866496SDavid Daney 
223af866496SDavid Daney /* These macros simplify the process of creating common IO addresses */
224af866496SDavid Daney #define CVMX_ADD_SEG(segment, add) ((((uint64_t)segment) << 62) | (add))
225af866496SDavid Daney #ifndef CVMX_ADD_IO_SEG
226af866496SDavid Daney #define CVMX_ADD_IO_SEG(add) CVMX_ADD_SEG(CVMX_IO_SEG, (add))
227af866496SDavid Daney #endif
228af866496SDavid Daney #define CVMX_ADDR_DIDSPACE(did) (((CVMX_IO_SEG) << 22) | ((1ULL) << 8) | (did))
229af866496SDavid Daney #define CVMX_ADDR_DID(did) (CVMX_ADDR_DIDSPACE(did) << 40)
230af866496SDavid Daney #define CVMX_FULL_DID(did, subdid) (((did) << 3) | (subdid))
231af866496SDavid Daney 
232af866496SDavid Daney   /* from include/ncb_rsl_id.v */
233af866496SDavid Daney #define CVMX_OCT_DID_MIS 0ULL	/* misc stuff */
234af866496SDavid Daney #define CVMX_OCT_DID_GMX0 1ULL
235af866496SDavid Daney #define CVMX_OCT_DID_GMX1 2ULL
236af866496SDavid Daney #define CVMX_OCT_DID_PCI 3ULL
237af866496SDavid Daney #define CVMX_OCT_DID_KEY 4ULL
238af866496SDavid Daney #define CVMX_OCT_DID_FPA 5ULL
239af866496SDavid Daney #define CVMX_OCT_DID_DFA 6ULL
240af866496SDavid Daney #define CVMX_OCT_DID_ZIP 7ULL
241af866496SDavid Daney #define CVMX_OCT_DID_RNG 8ULL
242af866496SDavid Daney #define CVMX_OCT_DID_IPD 9ULL
243af866496SDavid Daney #define CVMX_OCT_DID_PKT 10ULL
244af866496SDavid Daney #define CVMX_OCT_DID_TIM 11ULL
245af866496SDavid Daney #define CVMX_OCT_DID_TAG 12ULL
246af866496SDavid Daney   /* the rest are not on the IO bus */
247af866496SDavid Daney #define CVMX_OCT_DID_L2C 16ULL
248af866496SDavid Daney #define CVMX_OCT_DID_LMC 17ULL
249af866496SDavid Daney #define CVMX_OCT_DID_SPX0 18ULL
250af866496SDavid Daney #define CVMX_OCT_DID_SPX1 19ULL
251af866496SDavid Daney #define CVMX_OCT_DID_PIP 20ULL
252af866496SDavid Daney #define CVMX_OCT_DID_ASX0 22ULL
253af866496SDavid Daney #define CVMX_OCT_DID_ASX1 23ULL
254af866496SDavid Daney #define CVMX_OCT_DID_IOB 30ULL
255af866496SDavid Daney 
256af866496SDavid Daney #define CVMX_OCT_DID_PKT_SEND       CVMX_FULL_DID(CVMX_OCT_DID_PKT, 2ULL)
257af866496SDavid Daney #define CVMX_OCT_DID_TAG_SWTAG      CVMX_FULL_DID(CVMX_OCT_DID_TAG, 0ULL)
258af866496SDavid Daney #define CVMX_OCT_DID_TAG_TAG1       CVMX_FULL_DID(CVMX_OCT_DID_TAG, 1ULL)
259af866496SDavid Daney #define CVMX_OCT_DID_TAG_TAG2       CVMX_FULL_DID(CVMX_OCT_DID_TAG, 2ULL)
260af866496SDavid Daney #define CVMX_OCT_DID_TAG_TAG3       CVMX_FULL_DID(CVMX_OCT_DID_TAG, 3ULL)
261af866496SDavid Daney #define CVMX_OCT_DID_TAG_NULL_RD    CVMX_FULL_DID(CVMX_OCT_DID_TAG, 4ULL)
262af866496SDavid Daney #define CVMX_OCT_DID_TAG_CSR        CVMX_FULL_DID(CVMX_OCT_DID_TAG, 7ULL)
263af866496SDavid Daney #define CVMX_OCT_DID_FAU_FAI        CVMX_FULL_DID(CVMX_OCT_DID_IOB, 0ULL)
264af866496SDavid Daney #define CVMX_OCT_DID_TIM_CSR        CVMX_FULL_DID(CVMX_OCT_DID_TIM, 0ULL)
265af866496SDavid Daney #define CVMX_OCT_DID_KEY_RW         CVMX_FULL_DID(CVMX_OCT_DID_KEY, 0ULL)
266af866496SDavid Daney #define CVMX_OCT_DID_PCI_6          CVMX_FULL_DID(CVMX_OCT_DID_PCI, 6ULL)
267af866496SDavid Daney #define CVMX_OCT_DID_MIS_BOO        CVMX_FULL_DID(CVMX_OCT_DID_MIS, 0ULL)
268af866496SDavid Daney #define CVMX_OCT_DID_PCI_RML        CVMX_FULL_DID(CVMX_OCT_DID_PCI, 0ULL)
269af866496SDavid Daney #define CVMX_OCT_DID_IPD_CSR        CVMX_FULL_DID(CVMX_OCT_DID_IPD, 7ULL)
270af866496SDavid Daney #define CVMX_OCT_DID_DFA_CSR        CVMX_FULL_DID(CVMX_OCT_DID_DFA, 7ULL)
271af866496SDavid Daney #define CVMX_OCT_DID_MIS_CSR        CVMX_FULL_DID(CVMX_OCT_DID_MIS, 7ULL)
272af866496SDavid Daney #define CVMX_OCT_DID_ZIP_CSR        CVMX_FULL_DID(CVMX_OCT_DID_ZIP, 0ULL)
273af866496SDavid Daney 
274af866496SDavid Daney #endif /* __CVMX_ADDRESS_H__ */
275