Как выделить память ION для предопределенного типа кучи? - PullRequest
0 голосов
/ 06 февраля 2019

Не могу найти документацию о распределителе ION.Я не знаю, как выделить непрерывную память для выбранного типа кучи, используя ion.

Я пытался выделить память, используя следующий код:

    struct ion_allocation_data arg_alloc;

    arg_alloc.len = len;
    arg_alloc.heap_mask = heap_mask;
    arg_alloc.flags = flags;
    arg_alloc.fd = 0;

    ret = ioctl(client, ION_IOC_ALLOC_V1, &arg_alloc);

Я не понимаюлогика, значение которой следует поместить в переменную heap_mask .

1 Ответ

0 голосов
/ 28 февраля 2019

Драйвер ION содержит аргумент команды ioctl «ION_IOC_HEAP_QUERY», который можно использовать для получения информации о кучах (имя, тип, идентификатор и т. Д.), Включенных на конкретной платформе.Пример реализации был найден по следующей ссылке :

int ion_query_heap_cnt(int fd, int* cnt) {
    int ret;
    struct ion_heap_query query;
    memset(&query, 0, sizeof(query));
    ret = ion_ioctl(fd, ION_IOC_HEAP_QUERY, &query);
    if (ret < 0) return ret;
    *cnt = query.cnt;
    return ret;
}

int ion_query_get_heaps(int fd, int cnt, void* buffers) {
    int ret;
    struct ion_heap_query query = {
        .cnt = cnt, .heaps = (uintptr_t)buffers,
    };
    ret = ion_ioctl(fd, ION_IOC_HEAP_QUERY, &query);
    return ret;
}

Пример использования этого API найден здесь :

static int find_ion_heap_id(int ion_client, char* name)
{
    int i, ret, cnt, heap_id = -1;
    struct ion_heap_data *data;
    ret = ion_query_heap_cnt(ion_client, &cnt);
    if (ret)
    {
        AERR("ion count query failed with %s", strerror(errno));
        return -1;
    }
    data = (struct ion_heap_data *)malloc(cnt * sizeof(*data));
    if (!data)
    {
        AERR("Error allocating data %s\n", strerror(errno));
        return -1;
    }
    ret = ion_query_get_heaps(ion_client, cnt, data);
    if (ret)
    {
        AERR("Error querying heaps from ion %s", strerror(errno));
    }
    else
    {
        for (i = 0; i < cnt; i++) {
            struct ion_heap_data *dat = (struct ion_heap_data *)data;
            if (strcmp(dat[i].name, name) == 0) {
                heap_id = dat[i].heap_id;
                break;
            }
        }
        if (i > cnt)
        {
            AERR("No System Heap Found amongst %d heaps\n", cnt);
            heap_id = -1;
        }
    }
    free(data);
    return heap_id;
}

Вот как получается heap_id.Чтобы получить heap_mask нам нужно:

heap_mask = (1 << heap_id);
...