int disk_client_read(struct disk_client *c, size_t num_sectors,
		     unsigned long start_sector,
		     read_callback_t cb, error_callback_t err)
{
    int slot_num, status;
    struct disk_client_slot *slot;

    if (channel_can_send(c->req_chan) && next_free_slot(c) >= 0) {
	slot_num = alloc_slot(c);
	slot = get_slot(c, slot_num);

	slot->cb.read = cb;
	slot->err = err;
	slot->msg.type = DISK_READ;
	slot->msg.start_sector = start_sector;
	slot->msg.num_sectors = num_sectors;
	slot->msg.handle = slot_num;

	status =channel_send(c->req_chan, &(slot->msg));
	if (status == CHANNEL_OK) {
	    return DISK_OK;
	} else {
	    printf("Error in channel send (read): %d\n", status);
	    return DISK_ERROR;
	}
    }

    return DISK_BUSY;
}
int disk_client_get_size(struct disk_client *c, size_callback_t cb, error_callback_t err)
{
    int slot_num, status;
    struct disk_client_slot *slot;

    if (channel_can_send(c->req_chan) && next_free_slot(c) >= 0) {
	slot_num = alloc_slot(c);
	slot = get_slot(c, slot_num);

	slot->cb.size = cb;
	slot->err = err;
	slot->msg.type = DISK_SIZE;
	slot->msg.handle = slot_num;

	status = channel_send(c->req_chan, &(slot->msg));
	if (status == CHANNEL_OK) {
	    return DISK_OK;
	} else {
	    printf("Error in channel send (size): %d\n", status);
	    return DISK_ERROR;
	}
    }

    return DISK_BUSY;
}
int disk_client_write(struct disk_client *c, size_t num_sectors,
		      unsigned long start_sector, unsigned char *buf,
		      write_callback_t cb, error_callback_t err)
{
    int slot_num, status;
    struct disk_client_slot *slot;

    if (channel_can_send(c->req_chan) && next_free_slot(c) >= 0) {
	slot_num = alloc_slot(c);
	slot = get_slot(c, slot_num);

	slot->cb.write = cb;
	slot->err = err;
	slot->msg.type = DISK_WRITE;
	slot->msg.start_sector = start_sector;
	slot->msg.num_sectors = num_sectors;
	slot->msg.handle = slot_num;

	memcpy(slot->msg.payload, buf, num_sectors * SECTOR_SIZE);

	status = channel_send(c->req_chan, &(slot->msg));
	if (status == CHANNEL_OK) {
	    return DISK_OK;
	} else {
	    printf("Error in channel send (write): %d\n", status);
	    return DISK_ERROR;
	}
    }

    return DISK_BUSY;
}
Esempio n. 4
0
int arch_install_hw_breakpoint(struct perf_event *bp)
{
	int i;

	if (counter_arch_bp(bp)->type == XTENSA_BREAKPOINT_EXECUTE) {
		/* Breakpoint */
		i = alloc_slot(this_cpu_ptr(bp_on_reg), XCHAL_NUM_IBREAK, bp);
		if (i < 0)
			return i;
		set_ibreak_regs(i, bp);

	} else {
		/* Watchpoint */
		i = alloc_slot(this_cpu_ptr(wp_on_reg), XCHAL_NUM_DBREAK, bp);
		if (i < 0)
			return i;
		set_dbreak_regs(i, bp);
	}
	return 0;
}
Esempio n. 5
0
File: node.c Progetto: taysom/tau
node_s *new_node (u8 *netaddr, unint size)
{
	node_s	*node;
	unint	slot = 0;
FN;
	if (size > NET_ADDR_SIZE) return NULL;
	node = kmalloc(sizeof(*node), GFP_ATOMIC);
	if (!node) goto exit;
	zero(*node);

	slot = alloc_slot(node);
	if (slot == NO_SLOT) {
		kfree(node);
		return NULL;
	}

	memcpy(node->n_netaddr, netaddr, size);
	add_node(node, size);
exit:
	return node;
}
Esempio n. 6
0
/*!
 * Place a key into a protected location for use only by cryptographic
 * algorithms.
 *
 * This only needs to be used to a) unwrap a key, or b) set up a key which
 * could be wrapped by calling #fsl_shw_extract_key() at some later time).
 *
 * The protected key will not be available for use until this operation
 * successfully completes.
 *
 * @bug This whole discussion needs review.
 *
 * This feature is not available for all platforms, nor for all algorithms and
 * modes.
 *
 * @param      user_ctx         A user context from #fsl_shw_register_user().
 * @param[in,out] key_info      The information about the key to be which will
 *                              be established.  In the create case, the key
 *                              length must be set.
 * @param      establish_type   How @a key will be interpreted to establish a
 *                              key for use.
 * @param key                   If @a establish_type is #FSL_KEY_WRAP_UNWRAP,
 *                              this is the location of a wrapped key.  If
 *                              @a establish_type is #FSL_KEY_WRAP_CREATE, this
 *                              parameter can be @a NULL.  If @a establish_type
 *                              is #FSL_KEY_WRAP_ACCEPT, this is the location
 *                              of a plaintext key.
 *
 * @return    A return code of type #fsl_shw_return_t.
 */
fsl_shw_return_t fsl_shw_establish_key(fsl_shw_uco_t * user_ctx,
				       fsl_shw_sko_t * key_info,
				       fsl_shw_key_wrap_t establish_type,
				       const uint8_t * key)
{
	fsl_shw_return_t ret = FSL_RETURN_ERROR_S;
	unsigned original_key_length = key_info->key_length;
	unsigned rounded_key_length;
	unsigned slot_allocated = 0;

	/* For now, only blocking mode calls are supported */
	if (!(user_ctx->flags & FSL_UCO_BLOCKING_MODE)) {
#ifdef DIAG_SECURITY_FUNC
		LOG_DIAG_ARGS("%s: Non-blocking call not supported\n",
			      __FUNCTION__);
#endif
		ret = FSL_RETURN_BAD_FLAG_S;
		goto out;
	}

	/*
	   HW keys are always 'established', but otherwise do not allow user
	   * to establish over the top of an established key.
	 */
	if ((key_info->flags & FSL_SKO_KEY_ESTABLISHED)
	    && !(key_info->flags & FSL_SKO_KEY_SELECT_PF_KEY)) {
#ifdef DIAG_SECURITY_FUNC
		LOG_DIAG_ARGS("%s: Key already established\n", __FUNCTION__);
#endif
		ret = FSL_RETURN_BAD_FLAG_S;
		goto out;
	}

	/* @bug VALIDATE KEY flags here -- SW or PRG/IIM_PRG */

	/* Write operations into SCC memory require word-multiple number of
	 * bytes.  For ACCEPT and CREATE functions, the key length may need
	 * to be rounded up.  Calculate. */
	if (LENGTH_PATCH && (original_key_length & LENGTH_PATCH_MASK) != 0) {
		rounded_key_length = original_key_length + LENGTH_PATCH
		    - (original_key_length & LENGTH_PATCH_MASK);
	} else {
		rounded_key_length = original_key_length;
	}

	/* SW keys need a place to live */
	if (key_info->flags & FSL_SKO_KEY_SW_KEY) {
		ret = alloc_slot(user_ctx, key_info);
		if (ret != FSL_RETURN_OK_S) {
#ifdef DIAG_SECURITY_FUNC
			LOG_DIAG("Slot allocation failed\n");
#endif
			goto out;
		}
		slot_allocated = 1;
	}

	switch (establish_type) {
	case FSL_KEY_WRAP_CREATE:
#ifdef DIAG_SECURITY_FUNC
		LOG_DIAG("Creating random key\n");
#endif
		ret = create(user_ctx, key_info);
		break;

	case FSL_KEY_WRAP_ACCEPT:
#ifdef DIAG_SECURITY_FUNC
		LOG_DIAG("Accepting plaintext key\n");
#endif
		ret = accept(user_ctx, key_info, key);
		break;

	case FSL_KEY_WRAP_UNWRAP:
#ifdef DIAG_SECURITY_FUNC
		LOG_DIAG("Unwrapping wrapped key\n");
#endif
		ret = unwrap(user_ctx, key_info, key);
		break;

	default:
		ret = FSL_RETURN_BAD_FLAG_S;
		break;
	}			/* switch */

      out:
	if (ret != FSL_RETURN_OK_S) {
		if (slot_allocated) {
			(void)dealloc_slot(user_ctx, key_info);
		}
		key_info->flags &= ~FSL_SKO_KEY_ESTABLISHED;
	} else {
		key_info->flags |= FSL_SKO_KEY_ESTABLISHED;
	}

	return ret;
}				/* end fn fsl_shw_establish_key */