res_mgmt.c

来自「6440linuxDriver的源代码」· C语言 代码 · 共 119 行

C
119
字号
#include "hba_header.h"#include "res_mgmt.h"#include "oss_wrapper.h"struct mv_request_pool *res_reserve_req_pool(MV_U32 mod_id,					     MV_U32 size,					     MV_U32 sg_count){	int i;	unsigned int mem_size;	struct mv_request_pool *pool;	struct _MV_Request *req;	MV_SG_Entry *sg;	MV_DBG(DMSG_RES, "module %u reserves request pool of size %lu.\n",	       mod_id,	       (unsigned long) (sizeof(struct _MV_Request) * size + 				sizeof(MV_SG_Entry)* sg_count * size));	/* 	 * since we almost always use sgd_t with pctx, we need x2 memory	 * than normal sgd_t table	 */	sg_count *= 2;	mem_size = sizeof(struct mv_request_pool);	pool = vmalloc(mem_size);	if (NULL == pool)		goto res_err_pool;	/* assuming its size is already 64bit-aligned */	mem_size = sizeof(struct _MV_Request) * size;	req = vmalloc(mem_size);	if (NULL == req)		goto res_err_req;	MV_ZeroMemory(req, mem_size);	mem_size = sizeof(MV_SG_Entry) * sg_count * size;	sg  = vmalloc(mem_size);	if (NULL == sg)		goto res_err_sg;	INIT_LIST_HEAD(&pool->free_list);	INIT_LIST_HEAD(&pool->use_list);	OSSW_INIT_SPIN_LOCK(&pool->lock);	pool->mod_id  = mod_id;	pool->size    = size;	pool->req_mem = (void *) req;		for (i = 0; i < size; i++) {		MV_DBG(DMSG_RES_FREQ, "req no.%d at %p with sg at %p.\n",		       i, req, sg);		OSSW_INIT_TIMER(&req->timer);		req->SG_Table.Entry_Ptr  = sg;		req->SG_Table.Max_Entry_Count = sg_count;		list_add_tail(&req->pool_entry, &pool->free_list);		req++;		sg += sg_count;	}			return pool;res_err_sg:	vfree(req);res_err_req:	vfree(pool);res_err_pool:	return NULL;}struct _MV_Request *res_get_req_from_pool(struct mv_request_pool *pool){	struct _MV_Request *req;	unsigned long flags;	BUG_ON(pool == NULL);	OSSW_SPIN_LOCK_IRQSAVE(&pool->lock, flags);	if (list_empty(&pool->free_list)) {		res_dump_pool_info(pool);		OSSW_SPIN_UNLOCK_IRQRESTORE(&pool->lock, flags);		return NULL;	}		req = list_entry(pool->free_list.next, struct _MV_Request, pool_entry);	MV_ZeroMvRequest(req); /* FIX: we can do better than this */	list_move_tail(pool->free_list.next, &pool->use_list);	OSSW_SPIN_UNLOCK_IRQRESTORE(&pool->lock, flags);		return req;}void res_free_req_to_pool(struct mv_request_pool *pool,			  struct _MV_Request *req){	unsigned long flags;	BUG_ON((NULL == pool) || (NULL == req));	OSSW_SPIN_LOCK_IRQSAVE(&pool->lock, flags);	list_move(&req->pool_entry, &pool->free_list);	OSSW_SPIN_UNLOCK_IRQRESTORE(&pool->lock, flags);}void res_dump_pool_info(struct mv_request_pool *pool){	}void res_release_req_pool(struct mv_request_pool *pool){	BUG_ON(NULL == pool);		MV_DBG(DMSG_RES, "module %d release pool at %p.\n",	       pool->mod_id, pool);	vfree(pool->req_mem);	vfree(pool);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?