*/
#include <barrelfish/barrelfish.h>
+#include <devif/queue_interface.h>
#include "region.h"
#include "dqi_debug.h"
/**
- * @brief initialized a region
- *
- * @param region Return pointer to the region
- * @param region_id The ID of the region,
- * @param cap Capability of the memory region
- *
- * @returns error on failure or SYS_ERR_OK on success
- */
-/*
-errval_t region_init_variable_sized(struct region** region,
- uint32_t region_id,
- struct capref* cap)
-{
- USER_PANIC("NIY for variable sized buffers\n");
- return SYS_ERR_OK;
-}
-*/
-/**
* @brief initialized a region from which only fixed size buffers are used
*
* @param region Return pointer to the region
* @param region_id The ID of the region,
* @param cap Capability of the memory region
- * @param len Length of the fixed sized buffers
*
* @returns error on failure or SYS_ERR_OK on success
*/
errval_t region_init(struct region** region,
- uint32_t region_id,
- struct capref* cap,
- size_t len)
+ regionid_t region_id,
+ struct capref* cap)
{
errval_t err;
struct frame_identity id;
tmp->base_addr = id.base;
tmp->len = id.bytes;
- // Init state for fixed buffer region
- tmp->fixed_size = true;
- tmp->next_buf = 0;
- tmp->num_buf = id.bytes/len;
- tmp->in_use = calloc(sizeof(bool)*tmp->num_buf, 1);
- if (region == NULL) {
- free(tmp);
- return LIB_ERR_MALLOC_FAIL;
- }
-
*region = tmp;
DQI_DEBUG("Initialize Region size=%ld addr=%16lx num_bufs=%ld \n",
*/
errval_t region_destroy(struct region* region)
{
- for (int i = 0; i < region->num_buf; i++) {
- if (region->in_use[i]) {
- DQI_DEBUG("Could not destroy region, some buffers stil in use \n");
- // TODO reasonable error;
- return -1;
- }
- }
-
- free(region->in_use);
free(region);
return SYS_ERR_OK;
}
* @brief Get a buffer from a region
*
* @param region The region to get the buffer from
+ * @param addr The physical address of the buffer
* @param len lenght of the buffer
- * @param base_addr Return pointer to the physical address
- * of the buffer
*
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_get_buffer(struct region* region,
- uint32_t* buffer_id,
- lpaddr_t* addr)
+errval_t region_get_buffer_id(struct region* region,
+ lpaddr_t addr,
+ bufferid_t* buffer_id)
{
- if (region->fixed_size) {
- uint32_t count = 0;
- // Try to find empty slot, If we did not find
- // a slot after making a whole round, return error
- while (count < region->num_buf+1) {
- if (!region->in_use[region->next_buf]) {
- *buffer_id = region->next_buf;
- *addr = (region->base_addr + (region->next_buf*
- region->buf_len));
- region->in_use[region->next_buf] = true;
- region->next_buf = (region->next_buf + 1) % region->num_buf;
-
- DQI_DEBUG("Got buffer id=%d addr=%16lx \n", *buffer_id, *addr);
- return SYS_ERR_OK;
- } else {
- region->next_buf = (region->next_buf + 1) % region->num_buf;
- count++;
- }
- }
-
- } else {
- USER_PANIC("NIY for variable sized buffers\n");
- }
-
- DQI_DEBUG("Failed to get buffer \n");
- // TODO reasonable error
- return -1;
+ *buffer_id = 0;
+ DQI_DEBUG("Got buffer id=%d addr=%16lx \n", *buffer_id, *addr);
+ return SYS_ERR_OK;
}
* @brief Return a buffer to the region
*
* @param region The region to return the buffer to
- * @param len Lenght of the buffer returned
* @param buffer_id The id of the buffer to return to the region
- * @param addr The physical address of the freed buffer
*
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_free_buffer(struct region* region,
- uint32_t buffer_id)
+errval_t region_free_buffer_id(struct region* region,
+ bufferid_t buffer_id)
{
- if (region->fixed_size) {
- // Can not free buffer that is not used
- if (region->in_use[buffer_id] != true) {
- // TODO reasonable error
- return -1;
- }
- region->in_use[buffer_id] = false;
- } else {
- USER_PANIC("NIY for variable sized buffers\n");
- }
-
DQI_DEBUG("Returned buffer id=%d \n", buffer_id);
return SYS_ERR_OK;
}
+
+/**
+ * @brief Return a if a buffer to the region is in use
+ *
+ * @param region The region to return the buffer to
+ * @param buffer_id The id of the buffer
+ *
+ * @returns true if the buffer is in use otherwise false
+ */
+bool region_buffer_id_in_use(struct region* region,
+ bufferid_t buffer_id)
+{
+ DQI_DEBUG("Returned buffer id=%d \n", buffer_id);
+ return true;
+}
+
#include <barrelfish/barrelfish.h>
+#include <devif/queue_interface.h>
struct region {
// ID of the region
- uint32_t region_id;
+ regionid_t region_id;
// Base address of the region
lpaddr_t base_addr;
// Capability of the region
struct capref* cap;
// Lenght of the memory region
size_t len;
-
- // Are the buffers fixed size?
- bool fixed_size;
- // State for fixed sized buffers
- size_t num_buf;
- size_t buf_len;
- size_t next_buf;
- bool* in_use;
+ //
};
/**
* @returns error on failure or SYS_ERR_OK on success
*/
errval_t region_init(struct region** region,
- uint32_t region_id,
- struct capref* cap,
- size_t len);
+ regionid_t region_id,
+ struct capref* cap);
/**
* @brief free up a region
*
errval_t region_destroy(struct region* region);
/**
- * @brief initialized a region from which only fixed size buffers are used
- *
- * @param region Return pointer to the region
- * @param region_id The ID of the region,
- * @param cap Capability of the memory region
- * @param len Length of the fixed sized buffers
- *
- * @returns error on failure or SYS_ERR_OK on success
- */
-/*
-errval_t region_init_variable_size(struct region** region,
- uint32_t region_id,
- struct capref* cap,
- size_t len);
-*/
-/**
- * @brief Get a buffer from a region
+ * @brief Get a buffer id from a region
*
* @param region The region to get the buffer from
+ * @param addr The physical address of the buffer
* @param buffer_id Return pointer to the buffer id of the buffer
- * @param addr Return pointer to the physical address
- * of the buffer
*
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_get_buffer(struct region* region,
- uint32_t* buffer_id,
- lpaddr_t* addr);
+errval_t region_get_buffer_id(struct region* region,
+ lpaddr_t addr,
+ bufferid_t* buffer_id);
/**
- * @brief Return a buffer to the region
+ * @brief Return a buffer id to the region
*
* @param region The region to return the buffer to
* @param buffer_id The id of the buffer to return to the region
- * @param addr The physical address of the freed buffer
*
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_free_buffer(struct region* region,
- uint32_t buffer_id);
+errval_t region_free_buffer_id(struct region* region,
+ bufferid_t buffer_id);
/**
*
* @returns true if the buffer is in use otherwise false
*/
-inline bool region_buffer_in_use(struct region* region,
- uint32_t buffer_id)
-{
- return region->in_use[buffer_id];
-}
-
+bool region_buffer_id_in_use(struct region* region,
+ bufferid_t buffer_id);
#endif /* REGION_H_ */
*/
errval_t region_pool_add_region(struct region_pool* pool,
struct capref cap,
- uint32_t* region_id)
+ regionid_t* region_id)
{
errval_t err;
struct region* region;
// TODO size
err = region_init(®ion,
pool->region_offset + pool->num_regions + offset,
- &cap, 4096);
+ &cap);
// insert into pool
pool->pool[region->region_id % pool->size] = region;
* @returns error on failure or SYS_ERR_OK on success
*/
errval_t region_pool_remove_region(struct region_pool* pool,
- uint32_t region_id,
+ regionid_t region_id,
struct capref* cap)
{
struct region* region;
* @returns error on failure or SYS_ERR_OK on success
*/
static errval_t region_pool_get_region(struct region_pool* pool,
- uint32_t region_id,
- struct region** region)
+ regionid_t region_id,
+ struct region** region)
{
*region = pool->pool[region_id % pool->size];
if (region == NULL) {
/**
- * @brief get a page sized buffer from a region of the pool
+ * @brief get a buffer id from a region
*
* @param pool The pool to get the region from
* @param region_id The id of the region to get the buffer from
+ * @param addr The physical address of the buffer
* @param buffer_id Return pointer to the buffer id
- * @param addr Return pointer to the physical address of the buffer
*
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
- uint32_t region_id,
- uint32_t* buffer_id,
- lpaddr_t* addr)
+errval_t region_pool_get_buffer_id_from_region(struct region_pool* pool,
+ regionid_t region_id,
+ lpaddr_t addr,
+ bufferid_t* buffer_id)
{
errval_t err;
struct region* region;
return err;
}
- // TODO size
- err = region_get_buffer(region, buffer_id, addr);
+ err = region_get_buffer_id(region, addr, buffer_id);
if (err_is_fail(err)) {
return err;
}
}
/**
- * @brief return a page sized buffer to a region of the pool
+ * @brief returns the buffer id to the pool of free ids
*
* @param pool The pool to get the region from
* @param region_id The id of the region to get the buffer from
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
- uint32_t region_id,
- uint32_t buffer_id)
+errval_t region_pool_return_buffer_id_to_region(struct region_pool* pool,
+ regionid_t region_id,
+ bufferid_t buffer_id)
{
errval_t err;
struct region* region;
}
// TODO size
- err = region_free_buffer(region, buffer_id);
+ err = region_free_buffer_id(region, buffer_id);
if (err_is_fail(err)) {
return err;
}
*
* @returns true if the buffer is in use otherwise false
*/
-bool region_pool_buffer_of_region_in_use(struct region_pool* pool,
- uint32_t region_id,
- uint32_t buffer_id)
+bool region_pool_buffer_id_of_region_in_use(struct region_pool* pool,
+ regionid_t region_id,
+ bufferid_t buffer_id)
{
errval_t err;
struct region* region;
return false;
}
- return region_buffer_in_use(region, buffer_id);
+ return region_buffer_id_in_use(region, buffer_id);
}
#include <barrelfish/barrelfish.h>
+#include <devif/queue_interface.h>
struct region_pool;
struct region;
*/
errval_t region_pool_add_region(struct region_pool* pool,
struct capref cap,
- uint32_t* region_id);
+ regionid_t* region_id);
/**
* @brief remove a memory region from the region pool
* @returns error on failure or SYS_ERR_OK on success
*/
errval_t region_pool_remove_region(struct region_pool* pool,
- uint32_t region_id,
+ regionid_t region_id,
struct capref* cap);
/**
*
* @param pool The pool to get the region from
* @param region_id The id of the region to get the buffer from
+ * @param addr The physical address of the buffer
* @param buffer_id Return pointer to the buffer id
- * @param addr Return pointer to the physical address of the buffer
*
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_pool_get_buffer_from_region(struct region_pool* pool,
- uint32_t region_id,
- uint32_t* buffer_id,
- lpaddr_t* addr);
+errval_t region_pool_get_buffer_id_from_region(struct region_pool* pool,
+ bufferid_t region_id,
+ lpaddr_t addr,
+ bufferid_t* buffer_id);
/**
* @brief return a page sized buffer to a region of the pool
* @returns error on failure or SYS_ERR_OK on success
*/
-errval_t region_pool_return_buffer_to_region(struct region_pool* pool,
- uint32_t region_id,
- uint32_t buffer_id);
+errval_t region_pool_return_buffer_id_to_region(struct region_pool* pool,
+ regionid_t region_id,
+ bufferid_t buffer_id);
/**
* @brief return if a buffer of a region is in use
*
* @returns error on failure or SYS_ERR_OK on success
*/
-bool region_pool_buffer_of_region_in_use(struct region_pool* pool,
- uint32_t region_id,
- uint32_t buffer_id);
+bool region_pool_buffer_id_of_region_in_use(struct region_pool* pool,
+ regionid_t region_id,
+ bufferid_t buffer_id);
#endif /* REGION_POOL_H_ */