2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #ifndef _SCI_BASE_LIBRARY_H_
55 #define _SCI_BASE_LIBRARY_H_
60 * @brief This file contains the protected interface structures, constants
61 * and interface methods for the SCI_BASE_LIBRARY object.
69 #include <dev/isci/scil/sci_library.h>
70 #include <dev/isci/scil/sci_pool.h>
71 #include <dev/isci/scil/sci_base_object.h>
72 #include <dev/isci/scil/sci_base_logger.h>
73 #include <dev/isci/scil/sci_controller_constants.h>
76 * @struct SCI_BASE_LIBRARY
78 * @brief This structure contains all of the objects common to all library
81 typedef struct SCI_BASE_LIBRARY
84 * This class derives directly from the base object class. As a result,
85 * the field is named "parent" and is the first field contained in the
88 SCI_BASE_OBJECT_T parent;
91 * This field provides the logger object to be utilized by all objects
92 * contained inside of a library.
94 SCI_BASE_LOGGER_T logger;
96 // Create a pool structure to manage free controller indices.
97 SCI_POOL_CREATE(controller_id_pool, U16, SCI_MAX_CONTROLLERS);
103 * @brief This method will construct the base library object.
105 * @param[in] this_library This parameter specifies the library object
107 * @param[in] max_controllers This parameter specifies the maximum number
108 * of controllers to be supported by this library.
112 void sci_base_library_construct(
113 SCI_BASE_LIBRARY_T * this_library,
118 * This macro provides common code for allocating a controller from a library.
119 * It will ensure that we successfully allocate an available controller index
120 * and return SCI_FAILURE_INSUFFICIENT_RESOURCES if unsuccessful.
122 #define SCI_BASE_LIBRARY_ALLOCATE_CONTROLLER( \
130 if (! sci_pool_empty((library)->parent.controller_id_pool)) \
132 sci_pool_get((library)->parent.controller_id_pool, index); \
133 *controller_ptr = (SCI_CONTROLLER_HANDLE_T) \
134 & (library)->controllers[index]; \
137 *rc = SCI_FAILURE_INSUFFICIENT_RESOURCES; \
141 * This macro provides common code for freeing a controller to a library.
142 * It calculates the index to the controller instance in the array by
143 * determining the offset.
145 #define SCI_BASE_LIBRARY_FREE_CONTROLLER( \
153 ((((char *)(controller)) - ((char *)(library)->controllers))\
154 / sizeof(CONTROLLER_TYPE)); \
156 if ( (index < SCI_MAX_CONTROLLERS) \
157 && (! sci_pool_full((library)->parent.controller_id_pool)) ) \
159 sci_pool_put((library)->parent.controller_id_pool, index); \
162 *rc = SCI_FAILURE_CONTROLLER_NOT_FOUND; \
168 * This macro provides common code for constructing library. It
169 * It initialize and fill the library's controller_id_pool.
171 #define SCI_BASE_LIBRARY_CONSTRUCT( \
179 U32 controller_index; \
180 sci_base_object_construct(&(base_library)->parent, &(base_library)->logger); \
181 sci_pool_initialize((base_library)->controller_id_pool); \
182 for (controller_index = 0; controller_index < max_controller_count; controller_index++) \
184 SCI_BASE_LIBRARY_FREE_CONTROLLER( \
186 &library->controllers[controller_index], \
195 #endif // __cplusplus
197 #endif // _SCI_BASE_LIBRARY_H_