2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #ifndef _SCI_BASE_LIBRARY_H_
57 #define _SCI_BASE_LIBRARY_H_
62 * @brief This file contains the protected interface structures, constants
63 * and interface methods for the SCI_BASE_LIBRARY object.
71 #include <dev/isci/scil/sci_library.h>
72 #include <dev/isci/scil/sci_pool.h>
73 #include <dev/isci/scil/sci_base_object.h>
74 #include <dev/isci/scil/sci_base_logger.h>
75 #include <dev/isci/scil/sci_controller_constants.h>
78 * @struct SCI_BASE_LIBRARY
80 * @brief This structure contains all of the objects common to all library
83 typedef struct SCI_BASE_LIBRARY
86 * This class derives directly from the base object class. As a result,
87 * the field is named "parent" and is the first field contained in the
90 SCI_BASE_OBJECT_T parent;
93 * This field provides the logger object to be utilized by all objects
94 * contained inside of a library.
96 SCI_BASE_LOGGER_T logger;
98 // Create a pool structure to manage free controller indices.
99 SCI_POOL_CREATE(controller_id_pool, U16, SCI_MAX_CONTROLLERS);
101 } SCI_BASE_LIBRARY_T;
105 * @brief This method will construct the base library object.
107 * @param[in] this_library This parameter specifies the library object
109 * @param[in] max_controllers This parameter specifies the maximum number
110 * of controllers to be supported by this library.
114 void sci_base_library_construct(
115 SCI_BASE_LIBRARY_T * this_library,
120 * This macro provides common code for allocating a controller from a library.
121 * It will ensure that we successfully allocate an available controller index
122 * and return SCI_FAILURE_INSUFFICIENT_RESOURCES if unsuccessful.
124 #define SCI_BASE_LIBRARY_ALLOCATE_CONTROLLER( \
132 if (! sci_pool_empty((library)->parent.controller_id_pool)) \
134 sci_pool_get((library)->parent.controller_id_pool, index); \
135 *controller_ptr = (SCI_CONTROLLER_HANDLE_T) \
136 & (library)->controllers[index]; \
139 *rc = SCI_FAILURE_INSUFFICIENT_RESOURCES; \
143 * This macro provides common code for freeing a controller to a library.
144 * It calculates the index to the controller instance in the array by
145 * determining the offset.
147 #define SCI_BASE_LIBRARY_FREE_CONTROLLER( \
155 ((((char *)(controller)) - ((char *)(library)->controllers))\
156 / sizeof(CONTROLLER_TYPE)); \
158 if ( (index < SCI_MAX_CONTROLLERS) \
159 && (! sci_pool_full((library)->parent.controller_id_pool)) ) \
161 sci_pool_put((library)->parent.controller_id_pool, index); \
164 *rc = SCI_FAILURE_CONTROLLER_NOT_FOUND; \
170 * This macro provides common code for constructing library. It
171 * It initialize and fill the library's controller_id_pool.
173 #define SCI_BASE_LIBRARY_CONSTRUCT( \
181 U32 controller_index; \
182 sci_base_object_construct(&(base_library)->parent, &(base_library)->logger); \
183 sci_pool_initialize((base_library)->controller_id_pool); \
184 for (controller_index = 0; controller_index < max_controller_count; controller_index++) \
186 SCI_BASE_LIBRARY_FREE_CONTROLLER( \
188 &library->controllers[controller_index], \
197 #endif // __cplusplus
199 #endif // _SCI_BASE_LIBRARY_H_