Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef51488f authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Garmond Leung
Browse files

audio: MMAP NOIRQ mode shareable file descriptor

Derive a shareable file descriptor for the DMA buffer
used for MMAP NOIRQ

Change-Id: Ibdd633fad35ed397f6de746e5755a02522e39777
parent 1608104d
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -4128,6 +4128,7 @@ static int out_create_mmap_buffer(const struct audio_stream_out *stream,
    unsigned int offset1;
    unsigned int frames1;
    const char *step = "";
    uint32_t mmap_size;

    ALOGV("%s", __func__);
    pthread_mutex_lock(&adev->lock);
@@ -4168,8 +4169,14 @@ static int out_create_mmap_buffer(const struct audio_stream_out *stream,
    }
    info->buffer_size_frames = pcm_get_buffer_size(out->pcm);
    info->burst_size_frames = out->config.period_size;
    info->shared_memory_fd = pcm_get_poll_fd(out->pcm);

    ret = platform_get_mmap_data_fd(adev->platform,
                                    out->pcm_device_id, 0 /*playback*/,
                                    &info->shared_memory_fd,
                                    &mmap_size);
    if (ret < 0) {
        step = "get_mmap_fd";
        goto exit;
    }
    memset(info->shared_memory_address, 0, pcm_frames_to_bytes(out->pcm,
                                                               info->buffer_size_frames));

+41 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@
#include <dirent.h>
#include <linux/msm_audio.h>

#if defined(PLATFORM_MSMFALCON)
#include <sound/devdep_params.h>
#endif

#ifdef DYNAMIC_LOG_ENABLED
#include <log_xml_parser.h>
#define LOG_MASK HAL_MOD_FILE_PLATFORM
@@ -7229,3 +7233,40 @@ int platform_get_max_codec_backend() {

    return MAX_CODEC_BACKENDS;
}

#if defined(PLATFORM_MSMFALCON)
int platform_get_mmap_data_fd(void *platform, int fe_dev, int dir, int *fd,
                              uint32_t *size)
{
    struct platform_data *my_data = (struct platform_data *)platform;
    struct audio_device *adev = my_data->adev;
    int hw_fd = -1;
    char dev_name[128];
    struct snd_pcm_mmap_fd mmap_fd;
    memset(&mmap_fd, 0, sizeof(mmap_fd));
    mmap_fd.dir = dir;
    snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
             adev->snd_card, HWDEP_FE_BASE+fe_dev);
    hw_fd = open(dev_name, O_RDONLY);
    if (hw_fd < 0) {
        ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
        return -1;
    }
    if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
        ALOGE("fe hw dep node ioctl failed");
        close(hw_fd);
        return -1;
    }
    *fd = mmap_fd.fd;
    *size = mmap_fd.size;
    close(hw_fd); // mmap_fd should still be valid
    return 0;
}
#else
int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused,
                              int dir __unused, int *fd __unused,
                              uint32_t *size __unused)
{
    return -1;
}
#endif
+6 −0
Original line number Diff line number Diff line
@@ -1368,3 +1368,9 @@ int platform_set_acdb_metainfo_key(void *platform __unused, char *name __unused,
{
    return 0;
}

int platform_get_mmap_data_fd(void *platform, int fe_dev, int dir, int *fd,
                              uint32_t *size)
{
    return -ENOSYS;
}
+40 −0
Original line number Diff line number Diff line
@@ -75,6 +75,9 @@
#endif

#include <linux/msm_audio.h>
#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
#include <sound/devdep_params.h>
#endif

#define LIB_ACDB_LOADER "libacdbloader.so"
#define CVD_VERSION_MIXER_CTL "CVD Version"
@@ -7008,3 +7011,40 @@ int platform_get_max_codec_backend() {

    return MAX_CODEC_BACKENDS;
}

#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
int platform_get_mmap_data_fd(void *platform, int fe_dev, int dir, int *fd,
                              uint32_t *size)
{
    struct platform_data *my_data = (struct platform_data *)platform;
    struct audio_device *adev = my_data->adev;
    int hw_fd = -1;
    char dev_name[128];
    struct snd_pcm_mmap_fd mmap_fd;
    memset(&mmap_fd, 0, sizeof(mmap_fd));
    mmap_fd.dir = dir;
    snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
             adev->snd_card, HWDEP_FE_BASE+fe_dev);
    hw_fd = open(dev_name, O_RDONLY);
    if (hw_fd < 0) {
        ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
        return -1;
    }
    if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
        ALOGE("fe hw dep node ioctl failed");
        close(hw_fd);
        return -1;
    }
    *fd = mmap_fd.fd;
    *size = mmap_fd.size;
    close(hw_fd); // mmap_fd should still be valid
    return 0;
}
#else
int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused,
                              int dir __unused, int *fd __unused,
                              uint32_t *size __unused)
{
    return -1;
}
#endif
+2 −0
Original line number Diff line number Diff line
@@ -230,4 +230,6 @@ int platform_get_max_mic_count(void *platform);
void platform_check_and_update_copp_sample_rate(void *platform, snd_device_t snd_device,
     unsigned int stream_sr,int *sample_rate);
int platform_get_max_codec_backend();
int platform_get_mmap_data_fd(void *platform, int dev, int dir,
                               int *fd, uint32_t *size);
#endif // AUDIO_PLATFORM_API_H