Esempio n. 1
0
/* 
 * Return -1 if there is some form of error (couldn't find ring
 * buffer, or buffer is of inappropriate size), 1 if there is no
 * error, but there is no available buffer, 0 if found_buff and
 * found_len are set to the buffer's values.
 *
 * See cos_types.h for a description of the structure of the buffer.
 */
int rb_retrieve_buff(struct thread *brand, int desired_len, 
		     void **found_buf, int *found_len)
{
	ring_buff_t *rb;
	int position;
	void *addr;
	vaddr_t kaddr;
	unsigned short int status, len;
	struct spd *bspd;
	
	assert(brand);
	rb = brand->k_rb;
	if (!rb) {
		return -1;
	}
	position = brand->rb_next;
	addr     = rb->packets[position].ptr;
	len      = rb->packets[position].len;
	status   = rb->packets[position].status;
	if (RB_READY != status || NULL == addr) {
		return 1;
	}
	if (len < desired_len) {
		printk("ring_buff: length of user buffer not sufficient.\n");
		return -1;
	}
	bspd = thd_get_thd_spd(brand);
	kaddr = chal_pgtbl_vaddr2kaddr(bspd->spd_info.pg_tbl, (unsigned long)addr);
	if (!kaddr || !user_struct_fits_on_page(kaddr, len)) {
		rb->packets[position].status = RB_ERR;
		brand->rb_next = (position+1) & (RB_SIZE-1);
		printk("ring_buff: user buffer either not in memory, or not page_aligned.\n");
		return -1;
	}

	assert(kaddr);
//	printk("kaddr to copy to is %x from ptr %x\n", kaddr, addr);
	*found_buf = (void*)kaddr;
	*found_len = len;
	
	rb->packets[position].status = RB_USED;
	brand->rb_next = (position+1) & (RB_SIZE-1);

	return 0;
}
Esempio n. 2
0
unsigned int *
pgtbl_module_to_vaddr(unsigned long addr)
{
	return (unsigned int *)chal_pgtbl_vaddr2kaddr((paddr_t)chal_va2pa(current->mm->pgd), addr);
}