예제 #1
0
void sst_restore_fw_context(void)
{
	struct snd_sst_ctxt_params fw_context;
	struct ipc_post *msg = NULL;

	pr_debug("restore_fw_context\n");
	/*check cpu type*/
	if (sst_drv_ctx->pci_id != SST_MFLD_PCI_ID)
		return;
		/*not supported for rest*/
	if (!sst_drv_ctx->fw_cntx_size)
		return;
		/*nothing to restore*/
	pr_debug("restoring context......\n");
	/*send msg to fw*/
	if (sst_create_large_msg(&msg))
		return;

	sst_fill_header(&msg->header, IPC_IA_SET_FW_CTXT, 1, 0);
	msg->header.part.data = sizeof(fw_context) + sizeof(u32);
	fw_context.address = virt_to_phys((void *)sst_drv_ctx->fw_cntx);
	fw_context.size = sst_drv_ctx->fw_cntx_size;
	memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
	memcpy(msg->mailbox_data + sizeof(u32),
				&fw_context, sizeof(fw_context));
	spin_lock(&sst_drv_ctx->list_spin_lock);
	list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
	spin_unlock(&sst_drv_ctx->list_spin_lock);
	sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
	return;
}
예제 #2
0
static void sst_save_dsp_context(void)
{
    struct snd_sst_ctxt_params fw_context;
    unsigned int pvt_id;
    struct ipc_post *msg = NULL;
    unsigned long irq_flags;

    /*check cpu type*/
    if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
        return;
    /*not supported for rest*/
    if (sst_drv_ctx->sst_state != SST_FW_RUNNING) {
        pr_debug("fw not running no context save ...\n");
        return;
    }

    /*send msg to fw*/
    if (sst_create_large_msg(&msg))
        return;
    pvt_id = sst_assign_pvt_id(sst_drv_ctx);
    sst_drv_ctx->alloc_block[0].sst_id = pvt_id;
    sst_drv_ctx->alloc_block[0].ops_block.condition = false;
    sst_drv_ctx->alloc_block[0].ops_block.on = true;
    sst_fill_header(&msg->header, IPC_IA_GET_FW_CTXT, 1, pvt_id);
    msg->header.part.data = sizeof(fw_context) + sizeof(u32);
    fw_context.address = virt_to_phys((void *)sst_drv_ctx->fw_cntx);
    fw_context.size = FW_CONTEXT_MEM;
    memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
    memcpy(msg->mailbox_data + sizeof(u32),
           &fw_context, sizeof(fw_context));
    spin_lock_irqsave(&sst_drv_ctx->ipc_spin_lock, irq_flags);
    list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
    spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
    sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
    /*wait for reply*/
    if (sst_wait_timeout(sst_drv_ctx,
                         &sst_drv_ctx->alloc_block[0].ops_block))
        pr_err("sst: err fw context save timeout  ...\n");
    sst_drv_ctx->alloc_block[0].sst_id = BLOCK_UNINIT;
    pr_debug("fw context saved  ...\n");
    return;
}
예제 #3
0
/**
* sst_stream_stream - Send msg for a pausing stream
* @str_id:	 stream ID
*
* This function is called by any function which wants to start
* a stream.
*/
int sst_start_stream(int str_id)
{
	int retval = 0;
	struct ipc_post *msg = NULL;
	struct stream_info *str_info;

	pr_debug("sst_start_stream for %d\n", str_id);
	str_info = get_stream_info(str_id);
	if (!str_info)
		return -EINVAL;
	if (str_info->status != STREAM_RUNNING)
		return -EBADRQC;

	if (sst_create_large_msg(&msg))
		return -ENOMEM;

	if (sst_drv_ctx->pci_id == SST_MRFLD_PCI_ID) {
		sst_fill_header_mrfld(&msg->mrfld_header,
				IPC_IA_START_STREAM, 1, str_id);
		msg->mrfld_header.p.header_low_payload =
				sizeof(u64) + sizeof(u64);
		memcpy(msg->mailbox_data,
			&msg->mrfld_header.p.header_high.full, sizeof(u32));
		memcpy(msg->mailbox_data + sizeof(u32),
			&msg->mrfld_header.p.header_low_payload, sizeof(u32));
		memset(msg->mailbox_data + sizeof(u64), 0, sizeof(u32));
	} else {
		sst_fill_header(&msg->header, IPC_IA_START_STREAM, 1, str_id);
		msg->header.part.data =  sizeof(u32) + sizeof(u32);
		memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
		memset(msg->mailbox_data + sizeof(u32), 0, sizeof(u32));
	}

	sst_drv_ctx->ops->sync_post_message(msg);
	return retval;
}
/*This function is called when any codec/post processing library
 needs to be downloaded*/
static int sst_download_library(const struct firmware *fw_lib,
                                struct snd_sst_lib_download_info *lib)
{
    /* send IPC message and wait */
    int i;
    u8 pvt_id;
    struct ipc_post *msg = NULL;
    union config_status_reg csr;
    struct snd_sst_str_type str_type = {0};
    int retval = 0;

    if (sst_create_large_msg(&msg))
        return -ENOMEM;

    pvt_id = sst_assign_pvt_id(sst_drv_ctx);
    i = sst_get_block_stream(sst_drv_ctx);
    pr_debug("alloc block allocated = %d, pvt_id %d\n", i, pvt_id);
    if (i < 0) {
        kfree(msg);
        return -ENOMEM;
    }
    sst_drv_ctx->alloc_block[i].sst_id = pvt_id;
    sst_fill_header(&msg->header, IPC_IA_PREP_LIB_DNLD, 1, pvt_id);
    msg->header.part.data = sizeof(u32) + sizeof(str_type);
    str_type.codec_type = lib->dload_lib.lib_info.lib_type;
    /*str_type.pvt_id = pvt_id;*/
    memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
    memcpy(msg->mailbox_data + sizeof(u32), &str_type, sizeof(str_type));
    spin_lock(&sst_drv_ctx->list_spin_lock);
    list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
    spin_unlock(&sst_drv_ctx->list_spin_lock);
    sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
    retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
    if (retval) {
        /* error */
        sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
        pr_err("Prep codec downloaded failed %d\n",
               retval);
        return -EIO;
    }
    pr_debug("FW responded, ready for download now...\n");
    /* downloading on success */
    mutex_lock(&sst_drv_ctx->sst_lock);
    sst_drv_ctx->sst_state = SST_FW_LOADED;
    mutex_unlock(&sst_drv_ctx->sst_lock);
    csr.full = readl(sst_drv_ctx->shim + SST_CSR);
    csr.part.run_stall = 1;
    sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);

    csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
    csr.part.bypass = 0x7;
    sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);

    sst_parse_fw_image(fw_lib);

    /* set the FW to running again */
    csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
    csr.part.bypass = 0x0;
    sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);

    csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
    csr.part.run_stall = 0;
    sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);

    /* send download complete and wait */
    if (sst_create_large_msg(&msg)) {
        sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
        return -ENOMEM;
    }

    sst_fill_header(&msg->header, IPC_IA_LIB_DNLD_CMPLT, 1, pvt_id);
    sst_drv_ctx->alloc_block[i].sst_id = pvt_id;
    msg->header.part.data = sizeof(u32) + sizeof(*lib);
    lib->pvt_id = pvt_id;
    memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
    memcpy(msg->mailbox_data + sizeof(u32), lib, sizeof(*lib));
    spin_lock(&sst_drv_ctx->list_spin_lock);
    list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
    spin_unlock(&sst_drv_ctx->list_spin_lock);
    sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
    pr_debug("Waiting for FW response Download complete\n");
    sst_drv_ctx->alloc_block[i].ops_block.condition = false;
    retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
    if (retval) {
        /* error */
        mutex_lock(&sst_drv_ctx->sst_lock);
        sst_drv_ctx->sst_state = SST_UN_INIT;
        mutex_unlock(&sst_drv_ctx->sst_lock);
        sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
        return -EIO;
    }

    pr_debug("FW success on Download complete\n");
    sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
    mutex_lock(&sst_drv_ctx->sst_lock);
    sst_drv_ctx->sst_state = SST_FW_RUNNING;
    mutex_unlock(&sst_drv_ctx->sst_lock);
    return 0;

}
예제 #5
0
int sst_alloc_stream_mfld(char *params)
{
	struct ipc_post *msg = NULL;
	struct snd_sst_alloc_params_mfld alloc_param;
	struct snd_sst_params *str_params;
	struct stream_info *str_info;
	unsigned int stream_ops, device;
	struct snd_sst_stream_params_mfld *sparams;
	unsigned int pcm_slot = 0, num_ch, pcm_wd_sz, sfreq;
	int str_id;
	u8 codec;
	u32 rb_size, rb_addr, period_count;
	unsigned long irq_flags;

	pr_debug("In %s\n", __func__);

	BUG_ON(!params);
	str_params = (struct snd_sst_params *)params;
	stream_ops = str_params->ops;
	codec = str_params->codec;
	device = str_params->device_type;
	num_ch = sst_get_num_channel(str_params);
	sfreq = sst_get_sfreq(str_params);
	pcm_wd_sz = sst_get_wdsize(str_params);
	rb_size = str_params->aparams.ring_buf_info[0].size;
	rb_addr = str_params->aparams.ring_buf_info[0].addr;
	period_count = str_params->aparams.frag_size / 4;


	pr_debug("period_size = %d\n", period_count);
	pr_debug("ring_buf_addr = 0x%x\n", rb_addr);
	pr_debug("ring_buf_size = %d\n", rb_size);
	pr_debug("device_type=%d\n", device);
	pr_debug("sfreq =%d\n", sfreq);
	pr_debug("stream_ops%d codec%d device%d\n", stream_ops, codec, device);


	sparams = kzalloc(sizeof(*sparams), GFP_KERNEL);
	if (!sparams) {
		pr_err("Unable to allocate snd_sst_stream_params\n");
		return -ENOMEM;
	}


	sparams->uc.pcm_params.codec = codec;
	sparams->uc.pcm_params.num_chan = num_ch;
	sparams->uc.pcm_params.pcm_wd_sz = pcm_wd_sz;
	sparams->uc.pcm_params.reserved = 0;
	sparams->uc.pcm_params.sfreq = sfreq;
	sparams->uc.pcm_params.ring_buffer_size = rb_size;
	sparams->uc.pcm_params.period_count = period_count;
	sparams->uc.pcm_params.ring_buffer_addr = rb_addr;



	if (sst_check_device_type(device, num_ch, &pcm_slot)) {
		kfree(sparams);
		return -EINVAL;
	}
	mutex_lock(&sst_drv_ctx->stream_lock);
	str_id = device;
	mutex_unlock(&sst_drv_ctx->stream_lock);
	pr_debug("slot %x\n", pcm_slot);

	/*allocate device type context*/
	sst_init_stream(&sst_drv_ctx->streams[str_id], codec,
			str_id, stream_ops, pcm_slot);
	/* send msg to FW to allocate a stream */
	if (sst_create_large_msg(&msg)) {
		kfree(sparams);
		return -ENOMEM;
	}

	alloc_param.str_type.codec_type = codec;
	alloc_param.str_type.str_type = SST_STREAM_TYPE_MUSIC;
	alloc_param.str_type.operation = stream_ops;
	alloc_param.str_type.protected_str = 0; /* non drm */
	alloc_param.str_type.time_slots = pcm_slot;
	alloc_param.str_type.reserved = 0;
	alloc_param.str_type.result = 0;

	sst_fill_header(&msg->header, IPC_IA_ALLOC_STREAM, 1, str_id);
	msg->header.part.data = sizeof(alloc_param) + sizeof(u32);
	memcpy(&alloc_param.stream_params, sparams,
			sizeof(*sparams));
	kfree(sparams);

	memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
	memcpy(msg->mailbox_data + sizeof(u32), &alloc_param,
			sizeof(alloc_param));
	str_info = &sst_drv_ctx->streams[str_id];
	str_info->ctrl_blk.condition = false;
	str_info->ctrl_blk.ret_code = 0;
	str_info->ctrl_blk.on = true;
	spin_lock_irqsave(&sst_drv_ctx->ipc_spin_lock, irq_flags);
	list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
	spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
	sst_drv_ctx->ops->post_message(&sst_drv_ctx->ipc_post_msg_wq);
	pr_debug("SST DBG:alloc stream done\n");
	return str_id;
}
예제 #6
0
/**
 * sst_alloc_stream - Send msg for a new stream ID
 *
 * @params:	stream params
 * @stream_ops:	operation of stream PB/capture
 * @codec:	codec for stream
 * @device:	device stream to be allocated for
 *
 * This function is called by any function which wants to start
 * a new stream. This also check if a stream exists which is idle
 * it initializes idle stream id to this request
 */
int sst_alloc_stream_clv(char *params)
{
	struct ipc_post *msg = NULL;
	struct snd_sst_alloc_params alloc_param;
	unsigned int pcm_slot = 0x03, num_ch;
	int str_id;
	struct snd_sst_params *str_params;
	struct snd_sst_stream_params *sparams;
	struct snd_sst_alloc_params_ext *aparams;
	struct stream_info *str_info;
	unsigned int stream_ops, device;
	unsigned long irq_flags;
	u8 codec;

	pr_debug("In %s\n", __func__);

	BUG_ON(!params);
	str_params = (struct snd_sst_params *)params;
	stream_ops = str_params->ops;
	codec = str_params->codec;
	device = str_params->device_type;
	sparams = &str_params->sparams;
	aparams = &str_params->aparams;
	num_ch = sst_get_num_channel(str_params);

	pr_debug("period_size = %d\n", aparams->frag_size);
	pr_debug("ring_buf_addr = 0x%x\n", aparams->ring_buf_info[0].addr);
	pr_debug("ring_buf_size = %d\n", aparams->ring_buf_info[0].size);
	pr_debug("In alloc device_type=%d\n", str_params->device_type);
	pr_debug("In alloc sg_count =%d\n", aparams->sg_count);

	mutex_lock(&sst_drv_ctx->stream_lock);
	str_id = get_clv_stream_id(device);
	mutex_unlock(&sst_drv_ctx->stream_lock);
	if (str_id <= 0)
		return -EBUSY;

	/*allocate device type context*/
	sst_init_stream(&sst_drv_ctx->streams[str_id], codec,
			str_id, stream_ops, pcm_slot);
	/* send msg to FW to allocate a stream */
	if (sst_create_large_msg(&msg))
		return -ENOMEM;

	alloc_param.str_type.codec_type = codec;
	alloc_param.str_type.str_type = SST_STREAM_TYPE_MUSIC;
	alloc_param.str_type.operation = stream_ops;
	alloc_param.str_type.protected_str = 0; /* non drm */
	alloc_param.str_type.time_slots = pcm_slot;
	alloc_param.str_type.reserved = 0;
	alloc_param.str_type.result = 0;
	memcpy(&alloc_param.stream_params, sparams,
			sizeof(struct snd_sst_stream_params));
	memcpy(&alloc_param.alloc_params, aparams,
			sizeof(struct snd_sst_alloc_params_ext));


	if (sst_drv_ctx->pci_id == SST_CLV_PCI_ID) {
		sst_fill_header(&msg->header, IPC_IA_ALLOC_STREAM, 1, str_id);
		msg->header.part.data = sizeof(alloc_param) + sizeof(u32);
		memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
		memcpy(msg->mailbox_data + sizeof(u32), &alloc_param,
			sizeof(alloc_param));
	} else {
		sst_fill_header_mrfld(&msg->mrfld_header, IPC_IA_ALLOC_STREAM,
								1, str_id);
		msg->mrfld_header.p.header_low_payload =
				sizeof(alloc_param) + sizeof(u64);
		memcpy(msg->mailbox_data, &msg->mrfld_header.p.header_high.full,
								sizeof(u32));
		memcpy(msg->mailbox_data + sizeof(u32),
			&msg->mrfld_header.p.header_low_payload, sizeof(u32));
		memcpy(msg->mailbox_data + sizeof(u64), &alloc_param,
			sizeof(alloc_param));
	}
	str_info = &sst_drv_ctx->streams[str_id];
	str_info->ctrl_blk.condition = false;
	str_info->ctrl_blk.ret_code = 0;
	str_info->ctrl_blk.on = true;
	str_info->num_ch = num_ch;
	spin_lock_irqsave(&sst_drv_ctx->ipc_spin_lock, irq_flags);
	list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
	spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
	sst_drv_ctx->ops->post_message(&sst_drv_ctx->ipc_post_msg_wq);
	return str_id;
}