1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
44 * Support library for the hardware Free Pool Allocator.
46 * <hr>$Revision: 70030 $<hr>
55 * Current state of all the pools. Use access functions
56 * instead of using it directly.
58 CVMX_SHARED cvmx_fpa_pool_info_t cvmx_fpa_pool_info[CVMX_FPA_NUM_POOLS];
62 * Setup a FPA pool to control a new block of memory. The
63 * buffer pointer must be a physical address.
65 * @param pool Pool to initialize
67 * @param name Constant character string to name this pool.
68 * String is not copied.
69 * @param buffer Pointer to the block of memory to use. This must be
70 * accessable by all processors and external hardware.
71 * @param block_size Size for each block controlled by the FPA
72 * @param num_blocks Number of blocks
74 * @return 0 on Success,
77 int cvmx_fpa_setup_pool(uint64_t pool, const char *name, void *buffer,
78 uint64_t block_size, uint64_t num_blocks)
83 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: NULL buffer pointer!\n");
86 if (pool >= CVMX_FPA_NUM_POOLS)
88 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Illegal pool!\n");
92 if (block_size < CVMX_FPA_MIN_BLOCK_SIZE)
94 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Block size too small.\n");
98 if (((unsigned long)buffer & (CVMX_FPA_ALIGNMENT-1)) != 0)
100 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Buffer not aligned properly.\n");
104 cvmx_fpa_pool_info[pool].name = name;
105 cvmx_fpa_pool_info[pool].size = block_size;
106 cvmx_fpa_pool_info[pool].starting_element_count = num_blocks;
107 cvmx_fpa_pool_info[pool].base = buffer;
112 cvmx_fpa_free(ptr, pool, 0);
119 * Shutdown a Memory pool and validate that it had all of
120 * the buffers originally placed in it. This should only be
121 * called by one processor after all hardware has finished
122 * using the pool. Most like you will want to have called
123 * cvmx_helper_shutdown_packet_io_global() before this
124 * function to make sure all FPA buffers are out of the packet
127 * @param pool Pool to shutdown
129 * @return Zero on success
130 * - Positive is count of missing buffers
131 * - Negative is too many buffers or corrupted pointers
133 uint64_t cvmx_fpa_shutdown_pool(uint64_t pool)
137 int expected_count = cvmx_fpa_pool_info[pool].starting_element_count;
138 uint64_t base = cvmx_ptr_to_phys(cvmx_fpa_pool_info[pool].base);
139 uint64_t finish = base + cvmx_fpa_pool_info[pool].size * expected_count;
145 void *ptr = cvmx_fpa_alloc(pool);
149 address = cvmx_ptr_to_phys(ptr);
150 if ((address >= base) && (address < finish) &&
151 (((address - base) % cvmx_fpa_pool_info[pool].size) == 0))
157 cvmx_dprintf("ERROR: cvmx_fpa_shutdown_pool: Illegal address 0x%llx in pool %s(%d)\n",
158 (unsigned long long)address, cvmx_fpa_pool_info[pool].name, (int)pool);
163 if (count < expected_count)
165 cvmx_dprintf("ERROR: cvmx_fpa_shutdown_pool: Pool %s(%d) missing %d buffers\n",
166 cvmx_fpa_pool_info[pool].name, (int)pool, expected_count - count);
168 else if (count > expected_count)
170 cvmx_dprintf("ERROR: cvmx_fpa_shutdown_pool: Pool %s(%d) had %d duplicate buffers\n",
171 cvmx_fpa_pool_info[pool].name, (int)pool, count - expected_count);
176 cvmx_dprintf("ERROR: cvmx_fpa_shutdown_pool: Pool %s(%d) started at 0x%llx, ended at 0x%llx, with a step of 0x%x\n",
177 cvmx_fpa_pool_info[pool].name, (int)pool, (unsigned long long)base, (unsigned long long)finish, (int)cvmx_fpa_pool_info[pool].size);
181 return expected_count - count;
184 uint64_t cvmx_fpa_get_block_size(uint64_t pool)
189 return CVMX_FPA_POOL_0_SIZE;
191 return CVMX_FPA_POOL_1_SIZE;
193 return CVMX_FPA_POOL_2_SIZE;
195 return CVMX_FPA_POOL_3_SIZE;
197 return CVMX_FPA_POOL_4_SIZE;
199 return CVMX_FPA_POOL_5_SIZE;
201 return CVMX_FPA_POOL_6_SIZE;
203 return CVMX_FPA_POOL_7_SIZE;