xref: /freebsd/sys/dev/dpaa/bman.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1*0aeed3e9SJustin Hibbits /*-
2*0aeed3e9SJustin Hibbits  * Copyright (c) 2011-2012 Semihalf.
3*0aeed3e9SJustin Hibbits  * All rights reserved.
4*0aeed3e9SJustin Hibbits  *
5*0aeed3e9SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
6*0aeed3e9SJustin Hibbits  * modification, are permitted provided that the following conditions
7*0aeed3e9SJustin Hibbits  * are met:
8*0aeed3e9SJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
9*0aeed3e9SJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
10*0aeed3e9SJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
11*0aeed3e9SJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
12*0aeed3e9SJustin Hibbits  *    documentation and/or other materials provided with the distribution.
13*0aeed3e9SJustin Hibbits  *
14*0aeed3e9SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*0aeed3e9SJustin Hibbits  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*0aeed3e9SJustin Hibbits  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*0aeed3e9SJustin Hibbits  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*0aeed3e9SJustin Hibbits  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*0aeed3e9SJustin Hibbits  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*0aeed3e9SJustin Hibbits  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*0aeed3e9SJustin Hibbits  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*0aeed3e9SJustin Hibbits  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*0aeed3e9SJustin Hibbits  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*0aeed3e9SJustin Hibbits  * SUCH DAMAGE.
25*0aeed3e9SJustin Hibbits  */
26*0aeed3e9SJustin Hibbits 
27*0aeed3e9SJustin Hibbits #ifndef _BMAN_H
28*0aeed3e9SJustin Hibbits #define _BMAN_H
29*0aeed3e9SJustin Hibbits 
30*0aeed3e9SJustin Hibbits #include <machine/vmparam.h>
31*0aeed3e9SJustin Hibbits 
32*0aeed3e9SJustin Hibbits #include <contrib/ncsw/inc/Peripherals/bm_ext.h>
33*0aeed3e9SJustin Hibbits 
34*0aeed3e9SJustin Hibbits /*
35*0aeed3e9SJustin Hibbits  * BMAN Configuration
36*0aeed3e9SJustin Hibbits  */
37*0aeed3e9SJustin Hibbits 
38*0aeed3e9SJustin Hibbits /* Maximum number of buffers in all BMAN pools */
39*0aeed3e9SJustin Hibbits #define BMAN_MAX_BUFFERS	4096
40*0aeed3e9SJustin Hibbits 
41*0aeed3e9SJustin Hibbits /*
42*0aeed3e9SJustin Hibbits  * Portal definitions
43*0aeed3e9SJustin Hibbits  */
44*0aeed3e9SJustin Hibbits #define BMAN_CE_PA(base)	(base)
45*0aeed3e9SJustin Hibbits #define BMAN_CI_PA(base)	((base) + 0x100000)
46*0aeed3e9SJustin Hibbits 
47*0aeed3e9SJustin Hibbits #define BMAN_PORTAL_CE_PA(base, n)	\
48*0aeed3e9SJustin Hibbits     (BMAN_CE_PA(base) + ((n) * BMAN_PORTAL_CE_SIZE))
49*0aeed3e9SJustin Hibbits #define BMAN_PORTAL_CI_PA(base, n)	\
50*0aeed3e9SJustin Hibbits     (BMAN_CI_PA(base) + ((n) * BMAN_PORTAL_CI_SIZE))
51*0aeed3e9SJustin Hibbits 
52*0aeed3e9SJustin Hibbits #define BMAN_CCSR_SIZE		0x1000
53*0aeed3e9SJustin Hibbits 
54*0aeed3e9SJustin Hibbits struct bman_softc {
55*0aeed3e9SJustin Hibbits 	device_t	sc_dev;			/* device handle */
56*0aeed3e9SJustin Hibbits 	int		sc_rrid;		/* register rid */
57*0aeed3e9SJustin Hibbits 	struct resource	*sc_rres;		/* register resource */
58*0aeed3e9SJustin Hibbits 	int		sc_irid;		/* interrupt rid */
59*0aeed3e9SJustin Hibbits 	struct resource	*sc_ires;		/* interrupt resource */
60*0aeed3e9SJustin Hibbits 
61*0aeed3e9SJustin Hibbits 	bool		sc_regs_mapped[MAXCPU];	/* register mapping status */
62*0aeed3e9SJustin Hibbits 
63*0aeed3e9SJustin Hibbits 	t_Handle	sc_bh;			/* BMAN handle */
64*0aeed3e9SJustin Hibbits 	t_Handle	sc_bph[MAXCPU];		/* BMAN portal handles */
65*0aeed3e9SJustin Hibbits 	vm_paddr_t	sc_bp_pa;		/* BMAN portals PA */
66*0aeed3e9SJustin Hibbits 	unsigned int	sc_bpool_cpu[BM_MAX_NUM_OF_POOLS];
67*0aeed3e9SJustin Hibbits };
68*0aeed3e9SJustin Hibbits 
69*0aeed3e9SJustin Hibbits /*
70*0aeed3e9SJustin Hibbits  * External API
71*0aeed3e9SJustin Hibbits  */
72*0aeed3e9SJustin Hibbits 
73*0aeed3e9SJustin Hibbits /*
74*0aeed3e9SJustin Hibbits  * @brief Function to create BMAN pool.
75*0aeed3e9SJustin Hibbits  *
76*0aeed3e9SJustin Hibbits  * @param bpid		The pointer to variable where Buffer Pool ID will be
77*0aeed3e9SJustin Hibbits  *			stored.
78*0aeed3e9SJustin Hibbits  *
79*0aeed3e9SJustin Hibbits  * @param bufferSize	The size of buffers in newly created pool.
80*0aeed3e9SJustin Hibbits  *
81*0aeed3e9SJustin Hibbits  * @param maxBuffers	The maximum number of buffers in software stockpile.
82*0aeed3e9SJustin Hibbits  *			Set to 0 if software stockpile should not be created.
83*0aeed3e9SJustin Hibbits  *
84*0aeed3e9SJustin Hibbits  * @param minBuffers	The minimum number of buffers in software stockpile.
85*0aeed3e9SJustin Hibbits  *			Set to 0 if software stockpile should not be created.
86*0aeed3e9SJustin Hibbits  *
87*0aeed3e9SJustin Hibbits  * @param allocBuffers	The number of buffers to preallocate during pool
88*0aeed3e9SJustin Hibbits  *			creation.
89*0aeed3e9SJustin Hibbits  *
90*0aeed3e9SJustin Hibbits  * @param f_GetBuf	The buffer allocating function. Called only by
91*0aeed3e9SJustin Hibbits  *			bman_pool_create() and bman_pool_fill().
92*0aeed3e9SJustin Hibbits  *
93*0aeed3e9SJustin Hibbits  * @param f_PutBuf	The buffer freeing function. Called only by
94*0aeed3e9SJustin Hibbits  *			bman_pool_destroy().
95*0aeed3e9SJustin Hibbits  *
96*0aeed3e9SJustin Hibbits  * @param dep_sw_entry	The software portal depletion entry threshold.
97*0aeed3e9SJustin Hibbits  *			Set to 0 if depletion should not be signaled on
98*0aeed3e9SJustin Hibbits  *			software portal.
99*0aeed3e9SJustin Hibbits  *
100*0aeed3e9SJustin Hibbits  * @param dep_sw_exit	The software portal depletion exit threshold.
101*0aeed3e9SJustin Hibbits  *			Set to 0 if depletion should not be signaled on
102*0aeed3e9SJustin Hibbits  *			software portal.
103*0aeed3e9SJustin Hibbits  *
104*0aeed3e9SJustin Hibbits  * @param dep_hw_entry	The hardware portal depletion entry threshold.
105*0aeed3e9SJustin Hibbits  *			Set to 0 if depletion should not be signaled on
106*0aeed3e9SJustin Hibbits  *			hardware portal.
107*0aeed3e9SJustin Hibbits  *
108*0aeed3e9SJustin Hibbits  * @param dep_hw_exit	The hardware portal depletion exit threshold.
109*0aeed3e9SJustin Hibbits  *			Set to 0 if depletion should not be signaled on
110*0aeed3e9SJustin Hibbits  *			hardware portal.
111*0aeed3e9SJustin Hibbits  *
112*0aeed3e9SJustin Hibbits  * @param f_Depletion	The software portal depletion notification function.
113*0aeed3e9SJustin Hibbits  *			Set to NULL if depletion notification is not used.
114*0aeed3e9SJustin Hibbits  *
115*0aeed3e9SJustin Hibbits  * @param h_BufferPool	The user provided buffer pool context passed to
116*0aeed3e9SJustin Hibbits  *			f_GetBuf, f_PutBuf and f_Depletion functions.
117*0aeed3e9SJustin Hibbits  *
118*0aeed3e9SJustin Hibbits  * @param f_PhysToVirt	The PA to VA translation function. Set to NULL if
119*0aeed3e9SJustin Hibbits  *			default	one should be used.
120*0aeed3e9SJustin Hibbits  *
121*0aeed3e9SJustin Hibbits  * @param f_VirtToPhys	The VA to PA translation function. Set to NULL if
122*0aeed3e9SJustin Hibbits  *			default one should be used.
123*0aeed3e9SJustin Hibbits  *
124*0aeed3e9SJustin Hibbits  * @returns		Handle to newly created BMAN pool or NULL on error.
125*0aeed3e9SJustin Hibbits  *
126*0aeed3e9SJustin Hibbits  * @cautions		If pool uses software stockpile, all accesses to given
127*0aeed3e9SJustin Hibbits  *			pool must be protected by lock. Even if only hardware
128*0aeed3e9SJustin Hibbits  *			portal depletion notification is used, the caller must
129*0aeed3e9SJustin Hibbits  *			provide valid @p f_Depletion function.
130*0aeed3e9SJustin Hibbits  */
131*0aeed3e9SJustin Hibbits t_Handle bman_pool_create(uint8_t *bpid, uint16_t bufferSize,
132*0aeed3e9SJustin Hibbits     uint16_t maxBuffers, uint16_t minBuffers, uint16_t allocBuffers,
133*0aeed3e9SJustin Hibbits     t_GetBufFunction *f_GetBuf, t_PutBufFunction *f_PutBuf,
134*0aeed3e9SJustin Hibbits     uint32_t dep_sw_entry, uint32_t dep_sw_exit, uint32_t dep_hw_entry,
135*0aeed3e9SJustin Hibbits     uint32_t dep_hw_exit, t_BmDepletionCallback *f_Depletion,
136*0aeed3e9SJustin Hibbits     t_Handle h_BufferPool, t_PhysToVirt *f_PhysToVirt,
137*0aeed3e9SJustin Hibbits     t_VirtToPhys *f_VirtToPhys);
138*0aeed3e9SJustin Hibbits 
139*0aeed3e9SJustin Hibbits /*
140*0aeed3e9SJustin Hibbits  * @brief Fill pool with buffers.
141*0aeed3e9SJustin Hibbits  *
142*0aeed3e9SJustin Hibbits  * The bman_pool_fill() function fills the BMAN pool with buffers. The buffers
143*0aeed3e9SJustin Hibbits  * are allocated through f_GetBuf function (see bman_pool_create() description).
144*0aeed3e9SJustin Hibbits  *
145*0aeed3e9SJustin Hibbits  * @param pool		The BMAN pool handle.
146*0aeed3e9SJustin Hibbits  * @param nbufs		The number of buffers to allocate. To maximize
147*0aeed3e9SJustin Hibbits  *			performance this value should be multiple of 8.
148*0aeed3e9SJustin Hibbits  *
149*0aeed3e9SJustin Hibbits  * @returns		Zero on success or error code on failure.
150*0aeed3e9SJustin Hibbits  */
151*0aeed3e9SJustin Hibbits int bman_pool_fill(t_Handle pool, uint16_t nbufs);
152*0aeed3e9SJustin Hibbits 
153*0aeed3e9SJustin Hibbits /*
154*0aeed3e9SJustin Hibbits  * @brief Destroy pool.
155*0aeed3e9SJustin Hibbits  *
156*0aeed3e9SJustin Hibbits  * The bman_pool_destroy() function destroys the BMAN pool. Buffers for pool
157*0aeed3e9SJustin Hibbits  * are free through f_PutBuf function (see bman_pool_create() description).
158*0aeed3e9SJustin Hibbits  *
159*0aeed3e9SJustin Hibbits  * @param pool		The BMAN pool handle.
160*0aeed3e9SJustin Hibbits  *
161*0aeed3e9SJustin Hibbits  * @returns		Zero on success or error code on failure.
162*0aeed3e9SJustin Hibbits  */
163*0aeed3e9SJustin Hibbits int bman_pool_destroy(t_Handle pool);
164*0aeed3e9SJustin Hibbits 
165*0aeed3e9SJustin Hibbits /*
166*0aeed3e9SJustin Hibbits  * @brief Get a buffer from BMAN pool.
167*0aeed3e9SJustin Hibbits  *
168*0aeed3e9SJustin Hibbits  * @param pool		The BMAN pool handle.
169*0aeed3e9SJustin Hibbits  *
170*0aeed3e9SJustin Hibbits  * @returns		Pointer to the buffer or NULL if pool is empty.
171*0aeed3e9SJustin Hibbits  */
172*0aeed3e9SJustin Hibbits void *bman_get_buffer(t_Handle pool);
173*0aeed3e9SJustin Hibbits 
174*0aeed3e9SJustin Hibbits /*
175*0aeed3e9SJustin Hibbits  * @brief Put a buffer to BMAN pool.
176*0aeed3e9SJustin Hibbits  *
177*0aeed3e9SJustin Hibbits  * @param pool		The BMAN pool handle.
178*0aeed3e9SJustin Hibbits  * @param buffer	The pointer to buffer.
179*0aeed3e9SJustin Hibbits  *
180*0aeed3e9SJustin Hibbits  * @returns		Zero on success or error code on failure.
181*0aeed3e9SJustin Hibbits  */
182*0aeed3e9SJustin Hibbits int bman_put_buffer(t_Handle pool, void *buffer);
183*0aeed3e9SJustin Hibbits 
184*0aeed3e9SJustin Hibbits /*
185*0aeed3e9SJustin Hibbits  * @brief Count free buffers in given pool.
186*0aeed3e9SJustin Hibbits  *
187*0aeed3e9SJustin Hibbits  * @param pool		The BMAN pool handle.
188*0aeed3e9SJustin Hibbits  *
189*0aeed3e9SJustin Hibbits  * @returns		Number of free buffers in pool.
190*0aeed3e9SJustin Hibbits  */
191*0aeed3e9SJustin Hibbits uint32_t bman_count(t_Handle pool);
192*0aeed3e9SJustin Hibbits 
193*0aeed3e9SJustin Hibbits /*
194*0aeed3e9SJustin Hibbits  * Bus i/f
195*0aeed3e9SJustin Hibbits  */
196*0aeed3e9SJustin Hibbits int bman_attach(device_t dev);
197*0aeed3e9SJustin Hibbits int bman_detach(device_t dev);
198*0aeed3e9SJustin Hibbits int bman_suspend(device_t dev);
199*0aeed3e9SJustin Hibbits int bman_resume(device_t dev);
200*0aeed3e9SJustin Hibbits int bman_shutdown(device_t dev);
201*0aeed3e9SJustin Hibbits 
202*0aeed3e9SJustin Hibbits #endif /* BMAN_H */
203