1 /***********************license start***************
2 * Copyright (c) 2003-2008 Cavium Networks (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 Networks 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
47 * Support library for the hardware Free Pool Allocator.
49 * <hr>$Revision: 41586 $<hr>
58 * Current state of all the pools. Use access functions
59 * instead of using it directly.
61 CVMX_SHARED cvmx_fpa_pool_info_t cvmx_fpa_pool_info[CVMX_FPA_NUM_POOLS];
65 * Setup a FPA pool to control a new block of memory. The
66 * buffer pointer must be a physical address.
68 * @param pool Pool to initialize
70 * @param name Constant character string to name this pool.
71 * String is not copied.
72 * @param buffer Pointer to the block of memory to use. This must be
73 * accessable by all processors and external hardware.
74 * @param block_size Size for each block controlled by the FPA
75 * @param num_blocks Number of blocks
77 * @return 0 on Success,
80 int cvmx_fpa_setup_pool(uint64_t pool, const char *name, void *buffer,
81 uint64_t block_size, uint64_t num_blocks)
86 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: NULL buffer pointer!\n");
89 if (pool >= CVMX_FPA_NUM_POOLS)
91 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Illegal pool!\n");
95 if (block_size < CVMX_FPA_MIN_BLOCK_SIZE)
97 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Block size too small.\n");
101 if (((unsigned long)buffer & (CVMX_FPA_ALIGNMENT-1)) != 0)
103 cvmx_dprintf("ERROR: cvmx_fpa_setup_pool: Buffer not aligned properly.\n");
107 cvmx_fpa_pool_info[pool].name = name;
108 cvmx_fpa_pool_info[pool].size = block_size;
109 cvmx_fpa_pool_info[pool].starting_element_count = num_blocks;
110 cvmx_fpa_pool_info[pool].base = buffer;
115 cvmx_fpa_free(ptr, pool, 0);
122 * Shutdown a Memory pool and validate that it had all of
123 * the buffers originally placed in it.
125 * @param pool Pool to shutdown
126 * @return Zero on success
127 * - Positive is count of missing buffers
128 * - Negative is too many buffers or corrupted pointers
130 uint64_t cvmx_fpa_shutdown_pool(uint64_t pool)
134 uint64_t base = cvmx_ptr_to_phys(cvmx_fpa_pool_info[pool].base);
135 uint64_t finish = base + cvmx_fpa_pool_info[pool].size * cvmx_fpa_pool_info[pool].starting_element_count;
142 ptr = cvmx_fpa_alloc(pool);
144 address = cvmx_ptr_to_phys(ptr);
149 if ((address >= base) && (address < finish) &&
150 (((address - base) % cvmx_fpa_pool_info[pool].size) == 0))
156 cvmx_dprintf("ERROR: cvmx_fpa_shutdown_pool: Illegal address 0x%llx in pool %s(%d)\n",
157 (unsigned long long)address, cvmx_fpa_pool_info[pool].name, (int)pool);
163 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
170 cvmx_dprintf("ERROR: cvmx_fpa_shutdown_pool: Pool %s(%d) started at 0x%llx, ended at 0x%llx, with a step of 0x%llx\n",
171 cvmx_fpa_pool_info[pool].name, (int)pool, (unsigned long long)base, (unsigned long long)finish, (unsigned long long)cvmx_fpa_pool_info[pool].size);
178 uint64_t cvmx_fpa_get_block_size(uint64_t pool)
182 case 0: return(CVMX_FPA_POOL_0_SIZE);
183 case 1: return(CVMX_FPA_POOL_1_SIZE);
184 case 2: return(CVMX_FPA_POOL_2_SIZE);
185 case 3: return(CVMX_FPA_POOL_3_SIZE);
186 case 4: return(CVMX_FPA_POOL_4_SIZE);
187 case 5: return(CVMX_FPA_POOL_5_SIZE);
188 case 6: return(CVMX_FPA_POOL_6_SIZE);
189 case 7: return(CVMX_FPA_POOL_7_SIZE);