2 * Copyright (c) 2011-2012 Semihalf.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <machine/vmparam.h>
34 #include <contrib/ncsw/inc/Peripherals/bm_ext.h>
40 /* Maximum number of buffers in all BMAN pools */
41 #define BMAN_MAX_BUFFERS 4096
46 #define BMAN_CE_PA(base) (base)
47 #define BMAN_CI_PA(base) ((base) + 0x100000)
49 #define BMAN_PORTAL_CE_PA(base, n) \
50 (BMAN_CE_PA(base) + ((n) * BMAN_PORTAL_CE_SIZE))
51 #define BMAN_PORTAL_CI_PA(base, n) \
52 (BMAN_CI_PA(base) + ((n) * BMAN_PORTAL_CI_SIZE))
54 #define BMAN_CCSR_SIZE 0x1000
57 device_t sc_dev; /* device handle */
58 int sc_rrid; /* register rid */
59 struct resource *sc_rres; /* register resource */
60 int sc_irid; /* interrupt rid */
61 struct resource *sc_ires; /* interrupt resource */
63 bool sc_regs_mapped[MAXCPU]; /* register mapping status */
65 t_Handle sc_bh; /* BMAN handle */
66 t_Handle sc_bph[MAXCPU]; /* BMAN portal handles */
67 vm_paddr_t sc_bp_pa; /* BMAN portals PA */
68 unsigned int sc_bpool_cpu[BM_MAX_NUM_OF_POOLS];
76 * @brief Function to create BMAN pool.
78 * @param bpid The pointer to variable where Buffer Pool ID will be
81 * @param bufferSize The size of buffers in newly created pool.
83 * @param maxBuffers The maximum number of buffers in software stockpile.
84 * Set to 0 if software stockpile should not be created.
86 * @param minBuffers The minimum number of buffers in software stockpile.
87 * Set to 0 if software stockpile should not be created.
89 * @param allocBuffers The number of buffers to preallocate during pool
92 * @param f_GetBuf The buffer allocating function. Called only by
93 * bman_pool_create() and bman_pool_fill().
95 * @param f_PutBuf The buffer freeing function. Called only by
96 * bman_pool_destroy().
98 * @param dep_sw_entry The software portal depletion entry threshold.
99 * Set to 0 if depletion should not be signaled on
102 * @param dep_sw_exit The software portal depletion exit threshold.
103 * Set to 0 if depletion should not be signaled on
106 * @param dep_hw_entry The hardware portal depletion entry threshold.
107 * Set to 0 if depletion should not be signaled on
110 * @param dep_hw_exit The hardware portal depletion exit threshold.
111 * Set to 0 if depletion should not be signaled on
114 * @param f_Depletion The software portal depletion notification function.
115 * Set to NULL if depletion notification is not used.
117 * @param h_BufferPool The user provided buffer pool context passed to
118 * f_GetBuf, f_PutBuf and f_Depletion functions.
120 * @param f_PhysToVirt The PA to VA translation function. Set to NULL if
121 * default one should be used.
123 * @param f_VirtToPhys The VA to PA translation function. Set to NULL if
124 * default one should be used.
126 * @returns Handle to newly created BMAN pool or NULL on error.
128 * @cautions If pool uses software stockpile, all accesses to given
129 * pool must be protected by lock. Even if only hardware
130 * portal depletion notification is used, the caller must
131 * provide valid @p f_Depletion function.
133 t_Handle bman_pool_create(uint8_t *bpid, uint16_t bufferSize,
134 uint16_t maxBuffers, uint16_t minBuffers, uint16_t allocBuffers,
135 t_GetBufFunction *f_GetBuf, t_PutBufFunction *f_PutBuf,
136 uint32_t dep_sw_entry, uint32_t dep_sw_exit, uint32_t dep_hw_entry,
137 uint32_t dep_hw_exit, t_BmDepletionCallback *f_Depletion,
138 t_Handle h_BufferPool, t_PhysToVirt *f_PhysToVirt,
139 t_VirtToPhys *f_VirtToPhys);
142 * @brief Fill pool with buffers.
144 * The bman_pool_fill() function fills the BMAN pool with buffers. The buffers
145 * are allocated through f_GetBuf function (see bman_pool_create() description).
147 * @param pool The BMAN pool handle.
148 * @param nbufs The number of buffers to allocate. To maximize
149 * performance this value should be multiple of 8.
151 * @returns Zero on success or error code on failure.
153 int bman_pool_fill(t_Handle pool, uint16_t nbufs);
156 * @brief Destroy pool.
158 * The bman_pool_destroy() function destroys the BMAN pool. Buffers for pool
159 * are free through f_PutBuf function (see bman_pool_create() description).
161 * @param pool The BMAN pool handle.
163 * @returns Zero on success or error code on failure.
165 int bman_pool_destroy(t_Handle pool);
168 * @brief Get a buffer from BMAN pool.
170 * @param pool The BMAN pool handle.
172 * @returns Pointer to the buffer or NULL if pool is empty.
174 void *bman_get_buffer(t_Handle pool);
177 * @brief Put a buffer to BMAN pool.
179 * @param pool The BMAN pool handle.
180 * @param buffer The pointer to buffer.
182 * @returns Zero on success or error code on failure.
184 int bman_put_buffer(t_Handle pool, void *buffer);
187 * @brief Count free buffers in given pool.
189 * @param pool The BMAN pool handle.
191 * @returns Number of free buffers in pool.
193 uint32_t bman_count(t_Handle pool);
198 int bman_attach(device_t dev);
199 int bman_detach(device_t dev);
200 int bman_suspend(device_t dev);
201 int bman_resume(device_t dev);
202 int bman_shutdown(device_t dev);