int q6usm_us_client_buf_alloc(unsigned int dir, struct us_client *usc, unsigned int bufsz, unsigned int bufcnt) { int rc = 0; struct us_port_data *port = NULL; unsigned int size = bufsz*bufcnt; size_t len; if ((usc == NULL) || ((dir != IN) && (dir != OUT)) || (size == 0) || (usc->session <= 0 || usc->session > USM_SESSION_MAX)) { pr_err("%s: wrong parameters: size=%d; bufcnt=%d\n", __func__, size, bufcnt); return -EINVAL; } mutex_lock(&usc->cmd_lock); port = &usc->port[dir]; /* The size to allocate should be multiple of 4K bytes */ size = PAGE_ALIGN(size); rc = msm_audio_ion_alloc("ultrasound_client", &port->client, &port->handle, size, &port->phys, &len, &port->data); if (rc) { pr_err("%s: US ION allocation failed, rc = %d\n", __func__, rc); mutex_unlock(&usc->cmd_lock); return -ENOMEM; } port->buf_cnt = bufcnt; port->buf_size = bufsz; pr_debug("%s: data[%p]; phys[%llx]; [%p]\n", __func__, (void *)port->data, (u64)port->phys, (void *)&port->phys); rc = q6usm_memory_map(port->phys, dir, size, 1, usc->session, (uint32_t *)port->ext); if (rc < 0) { pr_err("%s: CMD Memory_map failed\n", __func__); mutex_unlock(&usc->cmd_lock); q6usm_us_client_buf_free(dir, usc); q6usm_us_param_buf_free(dir, usc); } else { mutex_unlock(&usc->cmd_lock); rc = 0; } return rc; }
int rtac_allocate_cal_buffer(uint32_t cal_type) { int result = 0; int len; pr_debug("%s\n", __func__); if (cal_type >= MAX_RTAC_BLOCKS) { pr_err("%s: cal_type %d is invalid!\n", __func__, cal_type); result = -EINVAL; goto done; } if (rtac_cal[cal_type].cal_data.paddr != 0) { pr_err("%s: memory already allocated! cal_type %d, paddr 0x%x\n", __func__, cal_type, rtac_cal[cal_type].cal_data.paddr); result = -EPERM; goto done; } result = msm_audio_ion_alloc("rtac_client", &rtac_cal[cal_type].map_data.ion_client, &rtac_cal[cal_type].map_data.ion_handle, rtac_cal[cal_type].map_data.map_size, (ion_phys_addr_t *)&rtac_cal[cal_type].cal_data.paddr, (size_t *)&len, (void **)&rtac_cal[cal_type].cal_data.kvaddr); if (result < 0) { pr_err("%s: ION create client for RTAC failed\n", __func__); goto done; } pr_debug("%s: cal_type %d, paddr 0x%x, kvaddr 0x%x, map_size 0x%x\n", __func__, cal_type, rtac_cal[cal_type].cal_data.paddr, rtac_cal[cal_type].cal_data.kvaddr, rtac_cal[cal_type].map_data.map_size); done: return result; }
int q6usm_us_param_buf_alloc(unsigned int dir, struct us_client *usc, unsigned int bufsz) { int rc = 0; struct us_port_data *port = NULL; unsigned int size = bufsz; size_t len; if ((usc == NULL) || ((dir != IN) && (dir != OUT)) || (usc->session <= 0 || usc->session > USM_SESSION_MAX)) { pr_err("%s: wrong parameters: direction=%d, bufsz=%d\n", __func__, dir, bufsz); return -EINVAL; } mutex_lock(&usc->cmd_lock); port = &usc->port[dir]; if (bufsz == 0) { pr_debug("%s: bufsz=0, get/set param commands are forbidden\n", __func__); port->param_buf = NULL; mutex_unlock(&usc->cmd_lock); return rc; } /* The size to allocate should be multiple of 4K bytes */ size = PAGE_ALIGN(size); rc = msm_audio_ion_alloc("ultrasound_client", &port->param_client, &port->param_handle, size, &port->param_phys, &len, &port->param_buf); if (rc) { pr_err("%s: US ION allocation failed, rc = %d\n", __func__, rc); mutex_unlock(&usc->cmd_lock); return -ENOMEM; } port->param_buf_size = bufsz; pr_debug("%s: param_buf[%p]; param_phys[%llx]; [%p]\n", __func__, (void *)port->param_buf, (u64)port->param_phys, (void *)&port->param_phys); rc = q6usm_memory_map(port->param_phys, (IN | OUT), size, 1, usc->session, (uint32_t *)port->param_buf_mem_handle); if (rc < 0) { pr_err("%s: CMD Memory_map failed\n", __func__); mutex_unlock(&usc->cmd_lock); q6usm_us_client_buf_free(dir, usc); q6usm_us_param_buf_free(dir, usc); } else { mutex_unlock(&usc->cmd_lock); rc = 0; } return rc; }