Main Page | Directories | File List | Globals

resources.c File Reference

#include <agnix/agnix.h>
#include <asm/bitops.h>
#include <agnix/resources.h>
#include <agnix/spinlock.h>
#include <agnix/memory.h>
#include <agnix/console.h>
#include <asm/cpu_ops.h>

Include dependency graph for resources.c:

Go to the source code of this file.

Defines

#define MOD_NAME   "RES: "
#define GLOBAL_RESOURCE_LEN   64
#define GLOBAL_RESOURCE_DESC   0
#define RESOURCES_DEBUG   0

Functions

int get_free_resource (int resource_desc)
int put_free_resource (int resource_desc, int resource_bit)
int request_resource (int resource_desc, int resource_bit)
int register_resource (struct resource_s *resource)
void unregister_resource (int resource_desc)
int resources_init (void)

Variables

resource_s * resources [GLOBAL_RESOURCE_LEN]
u32 global_resource_bitmap [(GLOBAL_RESOURCE_LEN<< 5)+1]
resource_s global_resource


Define Documentation

#define GLOBAL_RESOURCE_DESC   0
 

Definition at line 24 of file resources.c.

Referenced by register_resource(), and resources_init().

#define GLOBAL_RESOURCE_LEN   64
 

Definition at line 23 of file resources.c.

Referenced by resources_init().

#define MOD_NAME   "RES: "
 

Definition at line 22 of file resources.c.

#define RESOURCES_DEBUG   0
 

Definition at line 26 of file resources.c.


Function Documentation

int get_free_resource int  resource_desc  ) 
 

Definition at line 38 of file resources.c.

References flags, and resources.

Referenced by file_install_fd(), get_free_arp_entry(), get_free_btree(), get_free_counter(), get_free_queue(), and register_resource().

00039 {
00040     struct resource_s * resource = resources[resource_desc];
00041     u32 *bitmap;
00042     int bitmap_len;
00043     int zero_bit;
00044     u32 flags;
00045 
00046     bitmap = resource->resource_bitmap;
00047     bitmap_len = resource->resource_len << 5;
00048 
00049     spin_lock_irqsave(&resource->resource_lock, flags);
00050     if ((zero_bit = find_first_zero_bit(bitmap, bitmap_len)) < bitmap_len)
00051         set_bit(zero_bit, bitmap);
00052     else
00053         zero_bit = -1;
00054         
00055     spin_unlock_irqrestore(&resource->resource_lock, flags);
00056     
00057     return zero_bit;
00058 }

int put_free_resource int  resource_desc,
int  resource_bit
 

Definition at line 60 of file resources.c.

References flags, MOD_NAME, printk(), and resources.

Referenced by dma_put_channel(), put_free_arp_entry(), put_free_btree(), put_free_counter(), and put_free_queue().

00061 {
00062     struct resource_s * resource = resources[resource_desc];
00063     u32 *bitmap;
00064     u32  flags;
00065     int  ret = 0;
00066 
00067     if (resource == NULL) {
00068         printk(MOD_NAME "resource is NULL\n");
00069         return -1;
00070     }
00071 
00072     bitmap = resource->resource_bitmap;
00073 
00074     spin_lock_irqsave(&resource->resource_lock, flags);
00075     if (!test_and_clear_bit(resource_bit, bitmap)) {
00076         printk(MOD_NAME "there is zero bit on %d position in a queue_bitmap", resource_bit);
00077         ret = -1;
00078     }
00079     spin_unlock_irqrestore(&resource->resource_lock, flags);
00080 
00081     return ret;
00082 }

Here is the call graph for this function:

int register_resource struct resource_s *  resource  ) 
 

Definition at line 115 of file resources.c.

References get_free_resource(), GLOBAL_RESOURCE_DESC, memset(), MOD_NAME, printk(), and resources.

Referenced by btree_init(), counters_init(), dma_chip_init(), files_create(), net_layer_2_arp_init(), and queues_init().

00116 {
00117     int resource_desc;
00118 
00119 #if RESOURCES_DEBUG
00120     printk(MOD_NAME "Registering %s resource\n", resource->resource_name);
00121 #endif
00122     
00123     resource_desc = get_free_resource(GLOBAL_RESOURCE_DESC);
00124     resources[resource_desc] = resource;    
00125     memset(resource->resource_bitmap, 0, resource->resource_len);
00126 
00127     return resource_desc;
00128 }

Here is the call graph for this function:

int request_resource int  resource_desc,
int  resource_bit
 

Definition at line 84 of file resources.c.

References flags, MOD_NAME, printk(), and resources.

Referenced by dma_request_channel().

00085 {
00086     struct resource_s * resource = resources[resource_desc];
00087     u32 *bitmap;
00088     int bitmap_len;
00089     int ret;
00090     u32 flags;
00091 
00092     if (resource == NULL) {
00093         printk(MOD_NAME "resource is NULL\n");
00094         return -1;
00095     }
00096 
00097     bitmap = resource->resource_bitmap;
00098     bitmap_len = resource->resource_len << 5;
00099 
00100     spin_lock_irqsave(&resource->resource_lock, flags);
00101     if (!test_and_set_bit(resource_bit, bitmap))
00102     {
00103         printk(MOD_NAME "%s requesting %d resource\n", resource->resource_name, resource_bit);
00104         ret = 0;
00105     } else {
00106         printk(MOD_NAME "%s resource %d is busy\n", resource->resource_name, resource_bit);
00107         ret = -1;
00108     }
00109     
00110     spin_unlock_irqrestore(&resource->resource_lock, flags);
00111     
00112     return ret;
00113 }

Here is the call graph for this function:

int resources_init void   ) 
 

Definition at line 134 of file resources.c.

References global_resource, global_resource_bitmap, GLOBAL_RESOURCE_DESC, GLOBAL_RESOURCE_LEN, MOD_NAME, printk(), and resources.

Referenced by start_kernel().

00135 {
00136     int i;
00137 
00138     printk(MOD_NAME "Initializing %s resource\n", global_resource.resource_name);
00139     
00140     spin_lock_init(&global_resource.resource_lock);    
00141     
00142     /* sanity loop */
00143     for (i = 0; i < GLOBAL_RESOURCE_LEN; i++) {
00144         resources[i] = NULL;
00145     }
00146     resources[GLOBAL_RESOURCE_DESC] = &global_resource;
00147     set_bit(GLOBAL_RESOURCE_DESC, global_resource_bitmap);
00148     
00149     return 0;
00150 }

Here is the call graph for this function:

void unregister_resource int  resource_desc  ) 
 

Definition at line 130 of file resources.c.

00131 {
00132 }


Variable Documentation

struct resource_s global_resource
 

Initial value:

 {
    .resource_name      = "global",
    .resource_bitmap    = global_resource_bitmap,
    .resource_len       = GLOBAL_RESOURCE_LEN,
}

Definition at line 32 of file resources.c.

Referenced by resources_init().

u32 global_resource_bitmap[(GLOBAL_RESOURCE_LEN<< 5)+1]
 

Definition at line 30 of file resources.c.

Referenced by resources_init().

struct resource_s* resources[GLOBAL_RESOURCE_LEN]
 

Definition at line 28 of file resources.c.

Referenced by get_free_resource(), put_free_resource(), register_resource(), request_resource(), and resources_init().

Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix