/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* structure used to keep track of resources */
typedef struct ioat_rs_s {
/*
* Bounds of resource allocation. We will start allocating at rs_min
* and rollover at rs_max+1 (rs_max is included). e.g. for rs_min=0
* and rs_max=7, we will have 8 total resources which can be alloced.
*/
/*
* rs_free points to an array of 64-bit values used to track resource
* allocation. rs_free_size is the free buffer size in bytes.
*/
/*
* last tracks the last alloc'd resource. This allows us to do a round
* robin allocation.
*/
} ioat_rs_t;
/*
* ioat_rs_init()
* Initialize the resource structure. This structure will be protected
* by a mutex at the iblock_cookie passed in. init() returns a handle to be
* used for the rest of the resource functions. This code is written assuming
* that min_val will be close to 0. Therefore, we will allocate the free
* buffer only taking max_val into account.
*/
void
{
/* alloc space for resource structure */
/*
* Test to see if the max value is 64-bit aligned. If so, we don't need
* to allocate an extra 64-bit word. alloc space for free buffer
* (8 bytes per uint64_t).
*/
if ((max_val & 0x3F) == 0) {
} else {
}
/* Initialize resource structure */
/* Mark all resources as free */
}
/* setup handle which is returned from this function */
}
/*
* ioat_rs_fini()
* Frees up the space allocated in init(). Notice that a pointer to the
* handle is used for the parameter. fini() will set the handle to NULL
* before returning.
*/
void
{
/* set handle to null. This helps catch bugs. */
}
/*
* ioat_rs_alloc()
* alloc a resource. If alloc fails, we are out of resources.
*/
int
{
/*
* Find a free resource. This will return out of the loop once it finds
* a free resource. There are a total of 'max'-'min'+1 resources.
* Performs a round robin allocation.
*/
/* if the next resource to check is free */
/* we are using this resource */
/* take it out of the free list */
/*
* increment the last count so we start checking the
* next resource on the next alloc(). Note the rollover
* at 'max'+1.
*/
}
/* unlock the resource structure */
return (DDI_SUCCESS);
}
/*
* This resource is not free, lets go to the next one. Note the
* rollover at 'max'.
*/
}
}
return (DDI_FAILURE);
}
/*
* ioat_rs_free()
* Free the previously alloc'd resource. Once a resource has been free'd,
* it can be used again when alloc is called.
*/
void
{
/* Put the resource back in the free list */
}