int smd_write(smd_channel_info_t *ch, void *data, uint32_t len, int ch_type) { smd_pkt_hdr smd_hdr; uint32_t size = 0; memset(&smd_hdr, 0, sizeof(smd_pkt_hdr)); if(len + sizeof(smd_hdr) > ch->fifo_size) { dprintf(CRITICAL,"%s: len is greater than fifo sz\n", __func__); return -1; } /* Read the indices from smem */ ch->port_info = smem_get_alloc_entry(SMEM_SMD_BASE_ID + ch->alloc_entry.cid, &size); if(!ch->port_info) { dprintf(CRITICAL,"%s: unable to find index in smem\n", __func__); ASSERT(0); } if(!is_channel_open(ch)) { dprintf(CRITICAL,"%s: channel is not in OPEN state \n", __func__); return -1; } if(!ch->port_info->ch0.DTR_DSR) { dprintf(CRITICAL,"%s: DTR is off\n", __func__); return -1; } /* Clear the data_read flag */ ch->port_info->ch1.data_read = 0; /*copy the local buf to smd buf */ smd_hdr.pkt_size = len; memcpy_to_fifo(ch, (uint32_t *)&smd_hdr, sizeof(smd_hdr)); memcpy_to_fifo(ch, data, len); dsb(); /* Set the necessary flags */ ch->port_info->ch0.data_written = 1; ch->port_info->ch0.mask_recv_intr = 0; dsb(); smd_notify_rpm(); return 0; }
int smd_write(smd_channel_info_t *ch, void *data, uint32_t len, int ch_type) { smd_pkt_hdr smd_hdr; uint32_t size = 0; memset(&smd_hdr, 0, sizeof(smd_pkt_hdr)); if(len + sizeof(smd_hdr) > ch->fifo_size) { dprintf(CRITICAL,"%s: len is greater than fifo sz\n", __func__); return -1; } /* Read the indices from smem */ ch->port_info = smem_get_alloc_entry(SMEM_SMD_BASE_ID + ch->alloc_entry.cid, &size); if(!is_channel_open(ch)) { dprintf(CRITICAL,"%s: channel is not in OPEN state \n", __func__); return -1; } if(!ch->port_info->ch0.DTR_DSR) { dprintf(CRITICAL,"%s: DTR is off\n", __func__); return -1; } /* Clear the data_read flag */ ch->port_info->ch1.data_read = 0; /*copy the local buf to smd buf */ smd_hdr.pkt_size = len; memcpy(ch->send_buf + ch->port_info->ch0.write_index, &smd_hdr, sizeof(smd_hdr)); memcpy(ch->send_buf + ch->port_info->ch0.write_index + sizeof(smd_hdr), data, len); arch_invalidate_cache_range((addr_t)ch->send_buf+ch->port_info->ch0.write_index, sizeof(smd_hdr) + len); /* Update write index */ ch->port_info->ch0.write_index += sizeof(smd_hdr) + len; dsb(); /* Set the necessary flags */ ch->port_info->ch0.data_written = 1; ch->port_info->ch0.mask_recv_intr = 0; dsb(); smd_notify_rpm(); return 0; }