1 /***********************license start***************
2 * Author: Cavium Networks
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
7 * Copyright (c) 2003-2008 Cavium Networks
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 ***********************license end**************************************/
31 * Support library for the hardware Free Pool Allocator.
36 #include "cvmx-config.h"
42 * Current state of all the pools. Use access functions
43 * instead of using it directly.
45 CVMX_SHARED cvmx_fpa_pool_info_t cvmx_fpa_pool_info
[CVMX_FPA_NUM_POOLS
];
48 * Setup a FPA pool to control a new block of memory. The
49 * buffer pointer must be a physical address.
51 * @pool: Pool to initialize
53 * @name: Constant character string to name this pool.
54 * String is not copied.
55 * @buffer: Pointer to the block of memory to use. This must be
56 * accessable by all processors and external hardware.
57 * @block_size: Size for each block controlled by the FPA
58 * @num_blocks: Number of blocks
60 * Returns 0 on Success,
63 int cvmx_fpa_setup_pool(uint64_t pool
, const char *name
, void *buffer
,
64 uint64_t block_size
, uint64_t num_blocks
)
69 ("ERROR: cvmx_fpa_setup_pool: NULL buffer pointer!\n");
72 if (pool
>= CVMX_FPA_NUM_POOLS
) {
73 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Illegal pool!\n");
77 if (block_size
< CVMX_FPA_MIN_BLOCK_SIZE
) {
79 ("ERROR: cvmx_fpa_setup_pool: Block size too small.\n");
83 if (((unsigned long)buffer
& (CVMX_FPA_ALIGNMENT
- 1)) != 0) {
85 ("ERROR: cvmx_fpa_setup_pool: Buffer not aligned properly.\n");
89 cvmx_fpa_pool_info
[pool
].name
= name
;
90 cvmx_fpa_pool_info
[pool
].size
= block_size
;
91 cvmx_fpa_pool_info
[pool
].starting_element_count
= num_blocks
;
92 cvmx_fpa_pool_info
[pool
].base
= buffer
;
95 while (num_blocks
--) {
96 cvmx_fpa_free(ptr
, pool
, 0);
103 * Shutdown a Memory pool and validate that it had all of
104 * the buffers originally placed in it.
106 * @pool: Pool to shutdown
107 * Returns Zero on success
108 * - Positive is count of missing buffers
109 * - Negative is too many buffers or corrupted pointers
111 uint64_t cvmx_fpa_shutdown_pool(uint64_t pool
)
115 uint64_t base
= cvmx_ptr_to_phys(cvmx_fpa_pool_info
[pool
].base
);
118 cvmx_fpa_pool_info
[pool
].size
*
119 cvmx_fpa_pool_info
[pool
].starting_element_count
;
125 ptr
= cvmx_fpa_alloc(pool
);
127 address
= cvmx_ptr_to_phys(ptr
);
131 if ((address
>= base
) && (address
< finish
) &&
133 base
) % cvmx_fpa_pool_info
[pool
].size
) == 0)) {
137 ("ERROR: cvmx_fpa_shutdown_pool: Illegal address 0x%llx in pool %s(%d)\n",
138 (unsigned long long)address
,
139 cvmx_fpa_pool_info
[pool
].name
, (int)pool
);
145 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
152 ("ERROR: cvmx_fpa_shutdown_pool: Pool %s(%d) started at 0x%llx, ended at 0x%llx, with a step of 0x%llx\n",
153 cvmx_fpa_pool_info
[pool
].name
, (int)pool
,
154 (unsigned long long)base
, (unsigned long long)finish
,
155 (unsigned long long)cvmx_fpa_pool_info
[pool
].size
);
161 uint64_t cvmx_fpa_get_block_size(uint64_t pool
)
165 return CVMX_FPA_POOL_0_SIZE
;
167 return CVMX_FPA_POOL_1_SIZE
;
169 return CVMX_FPA_POOL_2_SIZE
;
171 return CVMX_FPA_POOL_3_SIZE
;
173 return CVMX_FPA_POOL_4_SIZE
;
175 return CVMX_FPA_POOL_5_SIZE
;
177 return CVMX_FPA_POOL_6_SIZE
;
179 return CVMX_FPA_POOL_7_SIZE
;