コード例 #1
0
ファイル: shm_api_linux.c プロジェクト: dejin/mymisc
static size_t MV_SHM_RevertVirtAddr_Base(shm_dev_t *shm_dev, void * ptr)
{
	shm_address_t *address_node;

	if (SHM_DEVICE_LOAD_COUNT <= 0) {
		MV_SHM_Print("user space MV_SHM_RevertVirtAddr_Base shm"
			" device not be open virtaddr[%08x]\n",(size_t)ptr);
		return ERROR_SHM_MALLOC_FAILED;
	}

	pthread_rwlock_rdlock(&shm_dev->addr.m_rb_rwlock);
	address_node =
		MV_SHM_lookup_virtaddress_node(
		&shm_dev->addr.m_virtaddr_root,(size_t)ptr);
	pthread_rwlock_unlock(&shm_dev->addr.m_rb_rwlock);

	if (address_node == NULL) {
		MV_SHM_Print("user space MV_SHM_RevertVirtAddr_Base can't found"
			" this virtaddr[%08x]\n",(size_t)ptr);
		return ERROR_SHM_MALLOC_FAILED;
	} else {
		return (size_t)((address_node->m_phyaddress +
			((size_t)ptr - address_node->m_virtaddress))
			- shm_dev->base.m_base_physaddr);
	}
}
コード例 #2
0
ファイル: shm_api_linux.c プロジェクト: dejin/mymisc
static HRESULT MV_SHM_UnmapVirt_Base(shm_dev_t *shm_dev, void* virtaddress)
{
	shm_address_t *address_node;
	shm_driver_operation_t op;
	int res = 0;

	if (SHM_DEVICE_LOAD_COUNT <= 0) {
		MV_SHM_Print("MV_SHM_UnmapVirt_Base shm device"
			" not be open\n");
		return E_NOTREADY;
	}

	pthread_rwlock_wrlock(&shm_dev->addr.m_rb_rwlock);
	address_node = MV_SHM_lookup_virtaddress_node(
		&shm_dev->addr.m_virtaddr_root,(size_t)virtaddress);
	if (address_node == NULL) {
		pthread_rwlock_unlock(&shm_dev->addr.m_rb_rwlock);
		MV_SHM_Print("MV_SHM_UnmapVirt_Base shm device"
			" not found virtaddress[%08x]\n",virtaddress);
		return S_OK;
	}
	op.m_param1 = address_node->m_phyaddress
			- shm_dev->base.m_base_physaddr;
	res = MV_SHM_Munmap_Base(address_node->m_virtaddress,
			address_node->m_size, shm_dev->mem_type);
	if (res == 0) {
		MV_SHM_delete_phyaddress_node(
			&shm_dev->addr.m_phyaddr_root,address_node);
		MV_SHM_delete_virtaddress_node(
			&shm_dev->addr.m_virtaddr_root,address_node);
		free(address_node);
	}
	pthread_rwlock_unlock(&shm_dev->addr.m_rb_rwlock);
	MV_SHM_Print("MV_SHM_UnmapVirt_Base shm device"
			" free offset[%08x]\n", op.m_param1);
	res = ioctl(shm_dev->base.m_fd, SHM_DEVICE_CMD_FREE, &op);
	CHECK_NOTERROR("ioctl", res, -1);

	return S_OK;
}
コード例 #3
0
static size_t MV_SHM_Base_RevertVirtAddr(shm_device_t *shm_dev, void *ptr)
{
	shm_address_t *address_node;
	if (shm_dev == NULL) {
		shm_error("kernel MV_SHM_Base_RevertVirtAddr parameter error\n");
		return ERROR_SHM_MALLOC_FAILED;
	}

	down_read(&shm_dev->m_rwsem);
	address_node =
	MV_SHM_lookup_virtaddress_node(
		&(shm_dev->m_virtaddr_root), (size_t) ptr);
	up_read(&shm_dev->m_rwsem);

	if (address_node == NULL) {
		shm_error("kernel MV_SHM_RevertCacheVirtAddr"
			" fail [%08x]\n",(size_t) ptr);
		return ERROR_SHM_MALLOC_FAILED;
	} else {
		return (size_t)((address_node->m_phyaddress +
			(((size_t) ptr) - address_node->m_virtaddress))
			- shm_dev->m_base);
	}
}