Merge "libadf: delete libadf & libadfhwc"

This commit is contained in:
Elliott Hughes 2021-01-22 23:37:48 +00:00 committed by Gerrit Code Review
commit ad5b717c5b
11 changed files with 0 additions and 2635 deletions

View file

@ -1,2 +0,0 @@
ghackmann@google.com
marissaw@google.com

View file

@ -1,26 +0,0 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_library {
name: "libadf",
recovery_available: true,
vendor_available: true,
vndk: {
enabled: true,
},
srcs: ["adf.cpp"],
cflags: ["-Werror"],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
}

View file

@ -1,746 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <algorithm>
#include <memory>
#include <vector>
#include <linux/limits.h>
#include <sys/ioctl.h>
#include <adf/adf.h>
#define ADF_BASE_PATH "/dev/"
static ssize_t adf_id_vector_to_array(const std::vector<adf_id_t> &in,
adf_id_t **out)
{
auto size = sizeof(in[0]) * in.size();
// We can't use new[] since the existing API says the caller should free()
// the returned array
auto ret = static_cast<adf_id_t *>(malloc(size));
if (!ret)
return -ENOMEM;
std::copy(in.begin(), in.end(), ret);
*out = ret;
return in.size();
}
static ssize_t adf_find_nodes(const char *pattern, adf_id_t **ids_out)
{
struct dirent *dirent;
std::unique_ptr<DIR, decltype(&closedir)>
dir{opendir(ADF_BASE_PATH), closedir};
if (!dir)
return -errno;
std::vector<adf_id_t> ids;
errno = 0;
while ((dirent = readdir(dir.get()))) {
adf_id_t id;
int matched = sscanf(dirent->d_name, pattern, &id);
if (matched < 0)
return -errno;
else if (matched == 1)
ids.push_back(id);
}
if (errno)
return -errno;
return adf_id_vector_to_array(ids, ids_out);
}
ssize_t adf_devices(adf_id_t **ids)
{
return adf_find_nodes("adf%u", ids);
}
int adf_device_open(adf_id_t id, int flags, struct adf_device *dev)
{
char filename[64];
dev->id = id;
snprintf(filename, sizeof(filename), ADF_BASE_PATH "adf%u", id);
dev->fd = open(filename, flags);
if (dev->fd < 0)
return -errno;
return 0;
}
void adf_device_close(struct adf_device *dev)
{
if (dev->fd >= 0)
close(dev->fd);
}
int adf_get_device_data(struct adf_device *dev, struct adf_device_data *data)
{
int err;
int ret = 0;
memset(data, 0, sizeof(*data));
err = ioctl(dev->fd, ADF_GET_DEVICE_DATA, data);
if (err < 0)
return -ENOMEM;
if (data->n_attachments)
data->attachments = new adf_attachment_config[data->n_attachments];
if (data->n_allowed_attachments)
data->allowed_attachments =
new adf_attachment_config[data->n_allowed_attachments];
if (data->custom_data_size)
data->custom_data = new char[data->custom_data_size];
err = ioctl(dev->fd, ADF_GET_DEVICE_DATA, data);
if (err < 0) {
ret = -errno;
adf_free_device_data(data);
}
return ret;
}
void adf_free_device_data(struct adf_device_data *data)
{
delete [] data->attachments;
data->attachments = nullptr;
delete [] data->allowed_attachments;
data->allowed_attachments = nullptr;
delete [] static_cast<char *>(data->custom_data);
data->custom_data = nullptr;
}
int adf_device_post(struct adf_device *dev,
adf_id_t *interfaces, size_t n_interfaces,
struct adf_buffer_config *bufs, size_t n_bufs,
void *custom_data, size_t custom_data_size)
{
int err;
struct adf_post_config data;
memset(&data, 0, sizeof(data));
data.interfaces = interfaces;
data.n_interfaces = n_interfaces;
data.bufs = bufs;
data.n_bufs = n_bufs;
data.custom_data = custom_data;
data.custom_data_size = custom_data_size;
err = ioctl(dev->fd, ADF_POST_CONFIG, &data);
if (err < 0)
return -errno;
return (int)data.complete_fence;
}
int adf_device_post_v2(struct adf_device *dev,
adf_id_t *interfaces, __u32 n_interfaces,
struct adf_buffer_config *bufs, __u32 n_bufs,
void *custom_data, __u64 custom_data_size,
enum adf_complete_fence_type complete_fence_type,
int *complete_fence)
{
int err;
struct adf_post_config_v2 data;
memset(&data, 0, sizeof(data));
data.interfaces = (uintptr_t)interfaces;
data.n_interfaces = n_interfaces;
data.bufs = (uintptr_t)bufs;
data.n_bufs = n_bufs;
data.custom_data = (uintptr_t)custom_data;
data.custom_data_size = custom_data_size;
data.complete_fence_type = complete_fence_type;
err = ioctl(dev->fd, ADF_POST_CONFIG_V2, &data);
if (err < 0)
return -errno;
if (complete_fence)
*complete_fence = data.complete_fence;
else if (data.complete_fence >= 0)
close(data.complete_fence);
return 0;
}
static int adf_device_attachment(struct adf_device *dev,
adf_id_t overlay_engine, adf_id_t interface, bool attach)
{
int err;
struct adf_attachment_config data;
memset(&data, 0, sizeof(data));
data.overlay_engine = overlay_engine;
data.interface = interface;
err = ioctl(dev->fd, attach ? ADF_ATTACH : ADF_DETACH, &data);
if (err < 0)
return -errno;
return 0;
}
int adf_device_attach(struct adf_device *dev, adf_id_t overlay_engine,
adf_id_t interface)
{
return adf_device_attachment(dev, overlay_engine, interface, true);
}
int adf_device_detach(struct adf_device *dev, adf_id_t overlay_engine,
adf_id_t interface)
{
return adf_device_attachment(dev, overlay_engine, interface, false);
}
ssize_t adf_interfaces(struct adf_device *dev, adf_id_t **interfaces)
{
char pattern[64];
snprintf(pattern, sizeof(pattern), "adf-interface%u.%%u", dev->id);
return adf_find_nodes(pattern, interfaces);
}
ssize_t adf_interfaces_for_overlay_engine(struct adf_device *dev,
adf_id_t overlay_engine, adf_id_t **interfaces)
{
struct adf_device_data data;
auto err = adf_get_device_data(dev, &data);
if (err < 0)
return err;
std::vector<adf_id_t> ids;
if (data.allowed_attachments != nullptr)
for (size_t i = 0; i < data.n_allowed_attachments; i++)
if (data.allowed_attachments[i].overlay_engine == overlay_engine)
ids.push_back(data.allowed_attachments[i].interface);
adf_free_device_data(&data);
return adf_id_vector_to_array(ids, interfaces);
}
static ssize_t adf_interfaces_filter(struct adf_device *dev,
adf_id_t *in, size_t n_in, adf_id_t **out,
bool (*filter)(struct adf_interface_data *data, __u32 match),
__u32 match)
{
std::vector<adf_id_t> ids;
for (size_t i = 0; i < n_in; i++) {
int fd = adf_interface_open(dev, in[i], O_RDONLY);
if (fd < 0)
return fd;
struct adf_interface_data data;
auto ret = adf_get_interface_data(fd, &data);
close(fd);
if (ret < 0)
return ret;
if (filter(&data, match))
ids.push_back(in[i]);
}
return adf_id_vector_to_array(ids, out);
}
static bool adf_interface_type_filter(struct adf_interface_data *data,
__u32 type)
{
return data->type == (enum adf_interface_type)type;
}
ssize_t adf_interfaces_filter_by_type(struct adf_device *dev,
enum adf_interface_type type,
adf_id_t *in, size_t n_in, adf_id_t **out)
{
return adf_interfaces_filter(dev, in, n_in, out, adf_interface_type_filter,
type);
}
static bool adf_interface_flags_filter(struct adf_interface_data *data,
__u32 flag)
{
return !!(data->flags & flag);
}
ssize_t adf_interfaces_filter_by_flag(struct adf_device *dev, __u32 flag,
adf_id_t *in, size_t n_in, adf_id_t **out)
{
return adf_interfaces_filter(dev, in, n_in, out, adf_interface_flags_filter,
flag);
}
int adf_interface_open(struct adf_device *dev, adf_id_t id, int flags)
{
char filename[64];
snprintf(filename, sizeof(filename), ADF_BASE_PATH "adf-interface%u.%u",
dev->id, id);
int fd = open(filename, flags);
if (fd < 0)
return -errno;
return fd;
}
int adf_get_interface_data(int fd, struct adf_interface_data *data)
{
int err;
int ret = 0;
memset(data, 0, sizeof(*data));
err = ioctl(fd, ADF_GET_INTERFACE_DATA, data);
if (err < 0)
return -errno;
if (data->n_available_modes)
data->available_modes = new drm_mode_modeinfo[data->n_available_modes];
if (data->custom_data_size)
data->custom_data = new char[data->custom_data_size];
err = ioctl(fd, ADF_GET_INTERFACE_DATA, data);
if (err < 0) {
ret = -errno;
adf_free_interface_data(data);
}
return ret;
}
void adf_free_interface_data(struct adf_interface_data *data)
{
delete [] data->available_modes;
delete [] static_cast<char *>(data->custom_data);
}
int adf_interface_blank(int fd, __u8 mode)
{
int err = ioctl(fd, ADF_BLANK, mode);
if (err < 0)
return -errno;
return 0;
}
int adf_interface_set_mode(int fd, struct drm_mode_modeinfo *mode)
{
int err = ioctl(fd, ADF_SET_MODE, mode);
if (err < 0)
return -errno;
return 0;
}
int adf_interface_simple_buffer_alloc(int fd, __u32 w, __u32 h,
__u32 format, __u32 *offset, __u32 *pitch)
{
int err;
struct adf_simple_buffer_alloc data;
memset(&data, 0, sizeof(data));
data.w = w;
data.h = h;
data.format = format;
err = ioctl(fd, ADF_SIMPLE_BUFFER_ALLOC, &data);
if (err < 0)
return -errno;
*offset = data.offset;
*pitch = data.pitch;
return (int)data.fd;
}
static void adf_interface_simple_post_config_buf(struct adf_buffer_config *buf,
__u32 overlay_engine, __u32 w, __u32 h, __u32 format, int buf_fd,
__u32 offset, __u32 pitch, int acquire_fence)
{
buf->overlay_engine = overlay_engine;
buf->w = w;
buf->h = h;
buf->format = format;
buf->fd[0] = buf_fd;
buf->offset[0] = offset;
buf->pitch[0] = pitch;
buf->n_planes = 1;
buf->acquire_fence = acquire_fence;
}
int adf_interface_simple_post(int fd, __u32 overlay_engine,
__u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
__u32 pitch, int acquire_fence)
{
int ret;
struct adf_simple_post_config data;
memset(&data, 0, sizeof(data));
adf_interface_simple_post_config_buf(&data.buf, overlay_engine, w, h, format,
buf_fd, offset, pitch, acquire_fence);
ret = ioctl(fd, ADF_SIMPLE_POST_CONFIG, &data);
if (ret < 0)
return -errno;
return (int)data.complete_fence;
}
int adf_interface_simple_post_v2(int fd, adf_id_t overlay_engine,
__u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
__u32 pitch, int acquire_fence,
enum adf_complete_fence_type complete_fence_type,
int *complete_fence)
{
int ret;
struct adf_simple_post_config_v2 data;
memset(&data, 0, sizeof(data));
adf_interface_simple_post_config_buf(&data.buf, overlay_engine, w, h, format,
buf_fd, offset, pitch, acquire_fence);
data.complete_fence_type = complete_fence_type;
ret = ioctl(fd, ADF_SIMPLE_POST_CONFIG_V2, &data);
if (ret < 0)
return -errno;
if (complete_fence)
*complete_fence = data.complete_fence;
else if (data.complete_fence >= 0)
close(data.complete_fence);
return 0;
}
ssize_t adf_overlay_engines(struct adf_device *dev, adf_id_t **overlay_engines)
{
char pattern[64];
snprintf(pattern, sizeof(pattern), "adf-overlay-engine%u.%%u", dev->id);
return adf_find_nodes(pattern, overlay_engines);
}
ssize_t adf_overlay_engines_for_interface(struct adf_device *dev,
adf_id_t interface, adf_id_t **overlay_engines)
{
struct adf_device_data data;
auto err = adf_get_device_data(dev, &data);
if (err < 0)
return err;
std::vector<adf_id_t> ids;
if (data.allowed_attachments != nullptr)
for (size_t i = 0; i < data.n_allowed_attachments; i++)
if (data.allowed_attachments[i].interface == interface)
ids.push_back(data.allowed_attachments[i].overlay_engine);
return adf_id_vector_to_array(ids, overlay_engines);
}
static ssize_t adf_overlay_engines_filter(struct adf_device *dev,
adf_id_t *in, size_t n_in, adf_id_t **out,
bool (*filter)(struct adf_overlay_engine_data *data, void *cookie),
void *cookie)
{
std::vector<adf_id_t> ids;
size_t i;
for (i = 0; i < n_in; i++) {
int fd = adf_overlay_engine_open(dev, in[i], O_RDONLY);
if (fd < 0)
return fd;
struct adf_overlay_engine_data data;
auto ret = adf_get_overlay_engine_data(fd, &data);
close(fd);
if (ret < 0)
return ret;
if (filter(&data, cookie))
ids.push_back(in[i]);
}
return adf_id_vector_to_array(ids, out);
}
struct format_filter_cookie {
const __u32 *formats;
size_t n_formats;
};
static bool adf_overlay_engine_format_filter(
struct adf_overlay_engine_data *data, void *cookie)
{
auto c = static_cast<format_filter_cookie *>(cookie);
size_t i;
for (i = 0; i < data->n_supported_formats; i++) {
size_t j;
for (j = 0; j < c->n_formats; j++)
if (data->supported_formats[i] == c->formats[j])
return true;
}
return false;
}
ssize_t adf_overlay_engines_filter_by_format(struct adf_device *dev,
const __u32 *formats, size_t n_formats, adf_id_t *in, size_t n_in,
adf_id_t **out)
{
struct format_filter_cookie cookie = { formats, n_formats };
return adf_overlay_engines_filter(dev, in, n_in, out,
adf_overlay_engine_format_filter, &cookie);
}
int adf_overlay_engine_open(struct adf_device *dev, adf_id_t id, int flags)
{
char filename[64];
snprintf(filename, sizeof(filename),
ADF_BASE_PATH "adf-overlay-engine%u.%u", dev->id, id);
int fd = open(filename, flags);
if (fd < 0)
return -errno;
return fd;
}
int adf_get_overlay_engine_data(int fd, struct adf_overlay_engine_data *data)
{
int err;
int ret = 0;
memset(data, 0, sizeof(*data));
err = ioctl(fd, ADF_GET_OVERLAY_ENGINE_DATA, data);
if (err < 0)
return -errno;
if (data->n_supported_formats)
data->supported_formats = new __u32[data->n_supported_formats];
if (data->custom_data_size)
data->custom_data = new char[data->custom_data_size];
err = ioctl(fd, ADF_GET_OVERLAY_ENGINE_DATA, data);
if (err < 0) {
ret = -errno;
adf_free_overlay_engine_data(data);
}
return ret;
}
void adf_free_overlay_engine_data(struct adf_overlay_engine_data *data)
{
delete [] data->supported_formats;
data->supported_formats = nullptr;
delete [] static_cast<char *>(data->custom_data);
data->custom_data = nullptr;
}
bool adf_overlay_engine_supports_format(int fd, __u32 format)
{
struct adf_overlay_engine_data data;
bool ret = false;
size_t i;
int err = adf_get_overlay_engine_data(fd, &data);
if (err < 0)
return false;
if (data.supported_formats != nullptr) {
for (i = 0; i < data.n_supported_formats; i++) {
if (data.supported_formats[i] == format) {
ret = true;
break;
}
}
}
adf_free_overlay_engine_data(&data);
return ret;
}
int adf_set_event(int fd, enum adf_event_type type, bool enabled)
{
struct adf_set_event data;
data.type = type;
data.enabled = enabled;
int err = ioctl(fd, ADF_SET_EVENT, &data);
if (err < 0)
return -errno;
return 0;
}
int adf_read_event(int fd, struct adf_event **event)
{
struct adf_event header;
struct event_with_data {
struct adf_event base;
uint8_t data[0];
};
using unique_event = std::unique_ptr<event_with_data, decltype(&free)>;
size_t data_size;
int err = read(fd, &header, sizeof(header));
if (err < 0)
return -errno;
if ((size_t)err < sizeof(header))
return -EIO;
if (header.length < sizeof(header))
return -EIO;
// Again, we can't use new[] since the existing API says the caller should
// free() the returned event
auto event_ptr = static_cast<event_with_data *>(malloc(header.length));
unique_event event_ret{event_ptr, free};
if (!event_ret)
return -ENOMEM;
data_size = header.length - sizeof(header);
memcpy(event_ret.get(), &header, sizeof(header));
ssize_t read_size = read(fd, &event_ret->data, data_size);
if (read_size < 0)
return -errno;
if ((size_t)read_size < data_size)
return -EIO;
*event = &event_ret.release()->base;
return 0;
}
void adf_format_str(__u32 format, char buf[ADF_FORMAT_STR_SIZE])
{
buf[0] = format & 0xFF;
buf[1] = (format >> 8) & 0xFF;
buf[2] = (format >> 16) & 0xFF;
buf[3] = (format >> 24) & 0xFF;
buf[4] = '\0';
}
static bool adf_find_simple_post_overlay_engine(struct adf_device *dev,
const __u32 *formats, size_t n_formats,
adf_id_t interface, adf_id_t *overlay_engine)
{
adf_id_t *engs = nullptr;
ssize_t n_engs = adf_overlay_engines_for_interface(dev, interface, &engs);
if (engs == nullptr)
return false;
adf_id_t *filtered_engs = nullptr;
ssize_t n_filtered_engs = adf_overlay_engines_filter_by_format(dev,
formats, n_formats, engs, n_engs, &filtered_engs);
free(engs);
if (filtered_engs == nullptr)
return false;
*overlay_engine = filtered_engs[0];
free(filtered_engs);
return true;
}
static const __u32 any_rgb_format[] = {
DRM_FORMAT_C8,
DRM_FORMAT_RGB332,
DRM_FORMAT_BGR233,
DRM_FORMAT_XRGB1555,
DRM_FORMAT_XBGR1555,
DRM_FORMAT_RGBX5551,
DRM_FORMAT_BGRX5551,
DRM_FORMAT_ARGB1555,
DRM_FORMAT_ABGR1555,
DRM_FORMAT_RGBA5551,
DRM_FORMAT_BGRA5551,
DRM_FORMAT_RGB565,
DRM_FORMAT_BGR565,
DRM_FORMAT_RGB888,
DRM_FORMAT_BGR888,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_XBGR8888,
DRM_FORMAT_RGBX8888,
DRM_FORMAT_BGRX8888,
DRM_FORMAT_XRGB2101010,
DRM_FORMAT_XBGR2101010,
DRM_FORMAT_RGBX1010102,
DRM_FORMAT_BGRX1010102,
DRM_FORMAT_ARGB2101010,
DRM_FORMAT_ABGR2101010,
DRM_FORMAT_RGBA1010102,
DRM_FORMAT_BGRA1010102,
DRM_FORMAT_ARGB8888,
DRM_FORMAT_ABGR8888,
DRM_FORMAT_RGBA8888,
DRM_FORMAT_BGRA8888,
};
int adf_find_simple_post_configuration(struct adf_device *dev,
const __u32 *formats, size_t n_formats,
adf_id_t *interface, adf_id_t *overlay_engine)
{
adf_id_t *intfs = NULL;
ssize_t n_intfs = adf_interfaces(dev, &intfs);
if (n_intfs < 0)
return n_intfs;
else if (!intfs)
return -ENODEV;
adf_id_t *primary_intfs = nullptr;
ssize_t n_primary_intfs = adf_interfaces_filter_by_flag(dev,
ADF_INTF_FLAG_PRIMARY, intfs, n_intfs, &primary_intfs);
free(intfs);
if (n_primary_intfs < 0)
return n_primary_intfs;
else if (!primary_intfs)
return -ENODEV;
if (!formats) {
formats = any_rgb_format;
n_formats = sizeof(any_rgb_format) / sizeof(any_rgb_format[0]);
}
bool found = false;
ssize_t i = 0;
for (i = 0; i < n_primary_intfs; i++) {
found = adf_find_simple_post_overlay_engine(dev, formats, n_formats,
primary_intfs[i], overlay_engine);
if (found) {
*interface = primary_intfs[i];
break;
}
}
free(primary_intfs);
if (!found)
return -ENODEV;
return 0;
}

View file

@ -1,295 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBADF_ADF_H_
#define _LIBADF_ADF_H_
#include <stdint.h>
#include <stdbool.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <video/adf.h>
typedef __u32 adf_id_t;
struct adf_device {
adf_id_t id;
int fd;
};
__BEGIN_DECLS
/**
* Enumerates all ADF devices.
*
* Returns the number of ADF devices, and sets ids to a list of device IDs.
* The caller must free() the returned list of device IDs.
*
* On error, returns -errno.
*/
ssize_t adf_devices(adf_id_t **ids);
/**
* Opens an ADF device.
*
* On error, returns -errno.
*/
int adf_device_open(adf_id_t id, int flags, struct adf_device *dev);
/**
* Closes an ADF device.
*/
void adf_device_close(struct adf_device *dev);
/**
* Reads the ADF device data.
*
* adf_get_device_data() allocates buffers inside data, which the caller
* must free by calling adf_free_device_data(). On error, returns -errno.
*/
int adf_get_device_data(struct adf_device *dev, struct adf_device_data *data);
/**
* Frees the device data returned by adf_get_device_data().
*/
void adf_free_device_data(struct adf_device_data *data);
/**
* Atomically posts a new display configuration to the specified interfaces.
*
* Returns a sync fence fd that will fire when the configuration is removed
* from the screen. On error, returns -errno.
*/
int adf_device_post(struct adf_device *dev,
adf_id_t *interfaces, size_t n_interfaces,
struct adf_buffer_config *bufs, size_t n_bufs,
void *custom_data, size_t custom_data_size);
/**
* Atomically posts a new display configuration to the specified interfaces.
*
* Compared to adf_device_post(), adf_device_post_v2():
*
* (*) allows the client to choose the kind of sync fence returned
* (through complete_fence_type)
*
* (*) stores the returned sync fence fd in a provided buffer, so the client
* can distinguish between a permission error (ret = -1) and a successful
* call that returns no fence (*complete_fence = -1)
*
* On error, returns -errno.
*
* On devices without the corresponding kernel support, returns -ENOTTY.
*/
int adf_device_post_v2(struct adf_device *dev,
adf_id_t *interfaces, __u32 n_interfaces,
struct adf_buffer_config *bufs, __u32 n_bufs,
void *custom_data, __u64 custom_data_size,
enum adf_complete_fence_type complete_fence_type,
int *complete_fence);
/**
* Attaches the specified interface and overlay engine.
*/
int adf_device_attach(struct adf_device *dev, adf_id_t overlay_engine,
adf_id_t interface);
/**
* Detaches the specified interface and overlay engine.
*/
int adf_device_detach(struct adf_device *dev, adf_id_t overlay_engine,
adf_id_t interface);
/**
* Enumerates all interfaces belonging to an ADF device.
*
* The caller must free() the returned list of interface IDs.
*/
ssize_t adf_interfaces(struct adf_device *dev, adf_id_t **interfaces);
/**
* Enumerates all interfaces which can be attached to the specified overlay
* engine.
*
* The caller must free() the returned list of interface IDs.
*/
ssize_t adf_interfaces_for_overlay_engine(struct adf_device *dev,
adf_id_t overlay_engine, adf_id_t **interfaces);
/**
* Filters a list of interfaces by type.
*
* Returns the number of matching interfaces, and sets out to a list of matching
* interface IDs. The caller must free() the returned list of interface IDs.
*
* On error, returns -errno.
*/
ssize_t adf_interfaces_filter_by_type(struct adf_device *dev,
enum adf_interface_type type,
adf_id_t *in, size_t n_in, adf_id_t **out);
/**
* Filters a list of interfaces by flag.
*
* The caller must free() the returned list of interface IDs.
*/
ssize_t adf_interfaces_filter_by_flag(struct adf_device *dev, __u32 flag,
adf_id_t *in, size_t n_in, adf_id_t **out);
/**
* Opens an ADF interface.
*
* Returns a file descriptor. The caller must close() the fd when done.
* On error, returns -errno.
*/
int adf_interface_open(struct adf_device *dev, adf_id_t id, int flags);
/**
* Reads the interface data.
*
* adf_get_interface_data() allocates buffers inside data, which the caller
* must free by calling adf_free_interface_data(). On error, returns -errno.
*/
int adf_get_interface_data(int fd, struct adf_interface_data *data);
/**
* Frees the interface data returned by adf_get_interface_data().
*/
void adf_free_interface_data(struct adf_interface_data *data);
/**
* Sets the interface's DPMS mode.
*/
int adf_interface_blank(int fd, __u8 mode);
/**
* Sets the interface's display mode.
*/
int adf_interface_set_mode(int fd, struct drm_mode_modeinfo *mode);
/**
* Allocates a single-plane RGB buffer of the specified size and format.
*
* Returns a dma-buf fd. On error, returns -errno.
*/
int adf_interface_simple_buffer_alloc(int fd, __u32 w, __u32 h,
__u32 format, __u32 *offset, __u32 *pitch);
/**
* Posts a single-plane RGB buffer to the display using the specified
* overlay engine.
*
* Returns a sync fence fd that will fire when the buffer is removed
* from the screen. On error, returns -errno.
*/
int adf_interface_simple_post(int fd, adf_id_t overlay_engine,
__u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
__u32 pitch, int acquire_fence);
/**
* Posts a single-plane RGB buffer to the display using the specified
* overlay engine.
*
* Compared to adf_interface_simple_post(), adf_interface_simple_post_v2():
*
* (*) allows the client to choose the kind of sync fence returned
* (through complete_fence_type)
*
* (*) stores the returned sync fence fd in a provided buffer, so the client
* can distinguish between a permission error (ret = -1) and a successful
* call that returns no fence (*complete_fence = -1)
*
* On error, returns -errno.
*
* On devices without the corresponding kernel support, returns -ENOTTY.
*/
int adf_interface_simple_post_v2(int fd, adf_id_t overlay_engine,
__u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset,
__u32 pitch, int acquire_fence,
enum adf_complete_fence_type complete_fence_type,
int *complete_fence);
/**
* Enumerates all overlay engines belonging to an ADF device.
*
* The caller must free() the returned list of overlay engine IDs.
*/
ssize_t adf_overlay_engines(struct adf_device *dev, adf_id_t **overlay_engines);
/**
* Enumerates all overlay engines which can be attached to the specified
* interface.
*
* The caller must free() the returned list of overlay engine IDs.
*/
ssize_t adf_overlay_engines_for_interface(struct adf_device *dev,
adf_id_t interface, adf_id_t **overlay_engines);
/**
* Filters a list of overlay engines by supported buffer format.
*
* Returns the overlay engines which support at least one of the specified
* formats. The caller must free() the returned list of overlay engine IDs.
*/
ssize_t adf_overlay_engines_filter_by_format(struct adf_device *dev,
const __u32 *formats, size_t n_formats, adf_id_t *in, size_t n_in,
adf_id_t **out);
/**
* Opens an ADF overlay engine.
*
* Returns a file descriptor. The caller must close() the fd when done.
* On error, returns -errno.
*/
int adf_overlay_engine_open(struct adf_device *dev, adf_id_t id, int flags);
/**
* Reads the overlay engine data.
*
* adf_get_overlay_engine_data() allocates buffers inside data, which the caller
* must free by calling adf_free_overlay_engine_data(). On error, returns
* -errno.
*/
int adf_get_overlay_engine_data(int fd, struct adf_overlay_engine_data *data);
/**
* Frees the overlay engine data returned by adf_get_overlay_engine_data().
*/
void adf_free_overlay_engine_data(struct adf_overlay_engine_data *data);
/**
* Returns whether the overlay engine supports the specified format.
*/
bool adf_overlay_engine_supports_format(int fd, __u32 format);
/**
* Subscribes or unsubscribes from the specified hardware event.
*/
int adf_set_event(int fd, enum adf_event_type type, bool enabled);
/**
* Reads one event from the fd, blocking if needed.
*
* The caller must free() the returned buffer. On error, returns -errno.
*/
int adf_read_event(int fd, struct adf_event **event);
#define ADF_FORMAT_STR_SIZE 5
/**
* Converts an ADF/DRM fourcc format to its string representation.
*/
void adf_format_str(__u32 format, char buf[ADF_FORMAT_STR_SIZE]);
/**
* Finds an appropriate interface and overlay engine for a simple post.
*
* Specifically, finds the primary interface, and an overlay engine
* that can be attached to the primary interface and supports one of the
* specified formats. The caller may pass a NULL formats list, to indicate that
* any RGB format is acceptable.
*
* On error, returns -errno.
*/
int adf_find_simple_post_configuration(struct adf_device *dev,
const __u32 *formats, size_t n_formats,
adf_id_t *interface, adf_id_t *overlay_engine);
__END_DECLS
#endif /* _LIBADF_ADF_H_ */

View file

@ -1,209 +0,0 @@
/****************************************************************************
****************************************************************************
***
*** This header was automatically generated from a Linux kernel header
*** of the same name, to make information necessary for userspace to
*** call into the kernel available to libc. It contains only constants,
*** structures, and macros generated from the original header, and thus,
*** contains no copyrightable information.
***
*** To edit the content of this header, modify the corresponding
*** source file (e.g. under external/kernel-headers/original/) then
*** run bionic/libc/kernel/tools/update_all.py
***
*** Any manual change here will be lost the next time this script will
*** be run. You've been warned!
***
****************************************************************************
****************************************************************************/
#ifndef _UAPI_VIDEO_ADF_H_
#define _UAPI_VIDEO_ADF_H_
#include <linux/ioctl.h>
#include <linux/types.h>
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#include <drm/drm_fourcc.h>
#include <drm/drm_mode.h>
#define ADF_NAME_LEN 32
#define ADF_MAX_CUSTOM_DATA_SIZE 4096
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
enum adf_interface_type {
ADF_INTF_DSI = 0,
ADF_INTF_eDP = 1,
ADF_INTF_DPI = 2,
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
ADF_INTF_VGA = 3,
ADF_INTF_DVI = 4,
ADF_INTF_HDMI = 5,
ADF_INTF_MEMORY = 6,
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
ADF_INTF_TYPE_DEVICE_CUSTOM = 128,
ADF_INTF_TYPE_MAX = (~(__u32) 0),
};
#define ADF_INTF_FLAG_PRIMARY (1 << 0)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_INTF_FLAG_EXTERNAL (1 << 1)
enum adf_event_type {
ADF_EVENT_VSYNC = 0,
ADF_EVENT_HOTPLUG = 1,
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
ADF_EVENT_DEVICE_CUSTOM = 128,
ADF_EVENT_TYPE_MAX = 255,
};
enum adf_complete_fence_type {
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
ADF_COMPLETE_FENCE_NONE = 0,
ADF_COMPLETE_FENCE_PRESENT = 1,
ADF_COMPLETE_FENCE_RELEASE = 2,
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct adf_set_event {
__u8 type;
__u8 enabled;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct adf_event {
__u8 type;
__u32 length;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct adf_vsync_event {
struct adf_event base;
__aligned_u64 timestamp;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct adf_hotplug_event {
struct adf_event base;
__u8 connected;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_MAX_PLANES 4
struct adf_buffer_config {
__u32 overlay_engine;
__u32 w;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u32 h;
__u32 format;
__s32 fd[ADF_MAX_PLANES];
__u32 offset[ADF_MAX_PLANES];
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u32 pitch[ADF_MAX_PLANES];
__u8 n_planes;
__s32 acquire_fence;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
struct adf_post_config {
size_t n_interfaces;
__u32 __user * interfaces;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
size_t n_bufs;
struct adf_buffer_config __user * bufs;
size_t custom_data_size;
void __user * custom_data;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__s32 complete_fence;
};
struct adf_post_config_v2 {
__u32 n_interfaces;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u64 interfaces;
__u32 n_bufs;
__u64 bufs;
__u64 custom_data_size;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u64 custom_data;
__s32 complete_fence;
__u8 complete_fence_type;
};
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
struct adf_simple_buffer_alloc {
__u16 w;
__u16 h;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u32 format;
__s32 fd;
__u32 offset;
__u32 pitch;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
};
struct adf_simple_post_config {
struct adf_buffer_config buf;
__s32 complete_fence;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
};
struct adf_simple_post_config_v2 {
struct adf_buffer_config buf;
__s32 complete_fence;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u8 complete_fence_type;
};
struct adf_attachment_config {
__u32 overlay_engine;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u32 interface;
};
struct adf_device_data {
char name[ADF_NAME_LEN];
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
size_t n_attachments;
struct adf_attachment_config __user * attachments;
size_t n_allowed_attachments;
struct adf_attachment_config __user * allowed_attachments;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
size_t custom_data_size;
void __user * custom_data;
};
#define ADF_MAX_ATTACHMENTS (4096 / sizeof(struct adf_attachment_config))
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct adf_interface_data {
char name[ADF_NAME_LEN];
__u32 type;
__u32 id;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u32 flags;
__u8 dpms_state;
__u8 hotplug_detect;
__u16 width_mm;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
__u16 height_mm;
struct drm_mode_modeinfo current_mode;
size_t n_available_modes;
struct drm_mode_modeinfo __user * available_modes;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
size_t custom_data_size;
void __user * custom_data;
};
#define ADF_MAX_MODES (4096 / sizeof(struct drm_mode_modeinfo))
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
struct adf_overlay_engine_data {
char name[ADF_NAME_LEN];
size_t n_supported_formats;
__u32 __user * supported_formats;
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
size_t custom_data_size;
void __user * custom_data;
};
#define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_IOCTL_TYPE 'D'
#define ADF_IOCTL_NR_CUSTOM 128
#define ADF_SET_EVENT _IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
#define ADF_BLANK _IOW(ADF_IOCTL_TYPE, 1, __u8)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
#define ADF_SET_MODE _IOW(ADF_IOCTL_TYPE, 3, struct drm_mode_modeinfo)
#define ADF_GET_DEVICE_DATA _IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
#define ADF_GET_INTERFACE_DATA _IOR(ADF_IOCTL_TYPE, 5, struct adf_interface_data)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_GET_OVERLAY_ENGINE_DATA _IOR(ADF_IOCTL_TYPE, 6, struct adf_overlay_engine_data)
#define ADF_SIMPLE_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 7, struct adf_simple_post_config)
#define ADF_SIMPLE_BUFFER_ALLOC _IOW(ADF_IOCTL_TYPE, 8, struct adf_simple_buffer_alloc)
#define ADF_ATTACH _IOW(ADF_IOCTL_TYPE, 9, struct adf_attachment_config)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ADF_DETACH _IOW(ADF_IOCTL_TYPE, 10, struct adf_attachment_config)
#define ADF_POST_CONFIG_V2 _IOW(ADF_IOCTL_TYPE, 11, struct adf_post_config_v2)
#define ADF_SIMPLE_POST_CONFIG_V2 _IOW(ADF_IOCTL_TYPE, 12, struct adf_simple_post_config_v2)
#endif
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */

View file

@ -1,386 +0,0 @@
/*
* Copyright (C) 2013 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _UAPI_VIDEO_ADF_H_
#define _UAPI_VIDEO_ADF_H_
#include <linux/ioctl.h>
#include <linux/types.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_mode.h>
#define ADF_NAME_LEN 32
#define ADF_MAX_CUSTOM_DATA_SIZE 4096
enum adf_interface_type {
ADF_INTF_DSI = 0,
ADF_INTF_eDP = 1,
ADF_INTF_DPI = 2,
ADF_INTF_VGA = 3,
ADF_INTF_DVI = 4,
ADF_INTF_HDMI = 5,
ADF_INTF_MEMORY = 6,
ADF_INTF_TYPE_DEVICE_CUSTOM = 128,
ADF_INTF_TYPE_MAX = (~(__u32)0),
};
#define ADF_INTF_FLAG_PRIMARY (1 << 0)
#define ADF_INTF_FLAG_EXTERNAL (1 << 1)
enum adf_event_type {
ADF_EVENT_VSYNC = 0,
ADF_EVENT_HOTPLUG = 1,
ADF_EVENT_DEVICE_CUSTOM = 128,
ADF_EVENT_TYPE_MAX = 255,
};
enum adf_complete_fence_type {
/* no fence */
ADF_COMPLETE_FENCE_NONE = 0,
/* fence fires when the configuration appears on the screen */
ADF_COMPLETE_FENCE_PRESENT = 1,
/* fence fires when the configuration leaves the screen */
ADF_COMPLETE_FENCE_RELEASE = 2,
};
/**
* struct adf_set_event - start or stop subscribing to ADF events
*
* @type: the type of event to (un)subscribe
* @enabled: subscribe or unsubscribe
*
* After subscribing to an event, userspace may poll() the ADF object's fd
* to wait for events or read() to consume the event's data.
*
* ADF reserves event types 0 to %ADF_EVENT_DEVICE_CUSTOM-1 for its own events.
* Devices may use event types %ADF_EVENT_DEVICE_CUSTOM to %ADF_EVENT_TYPE_MAX-1
* for driver-private events.
*/
struct adf_set_event {
__u8 type;
__u8 enabled;
};
/**
* struct adf_event - common header for ADF event data
*
* @type: event type
* @length: total size of event data, header inclusive
*/
struct adf_event {
__u8 type;
__u32 length;
};
/**
* struct adf_vsync_event - ADF vsync event
*
* @base: event header (see &struct adf_event)
* @timestamp: time of vsync event, in nanoseconds
*/
struct adf_vsync_event {
struct adf_event base;
__aligned_u64 timestamp;
};
/**
* struct adf_vsync_event - ADF display hotplug event
*
* @base: event header (see &struct adf_event)
* @connected: whether a display is now connected to the interface
*/
struct adf_hotplug_event {
struct adf_event base;
__u8 connected;
};
#define ADF_MAX_PLANES 4
/**
* struct adf_buffer_config - description of buffer displayed by adf_post_config
*
* @overlay_engine: id of the target overlay engine
* @w: width of display region in pixels
* @h: height of display region in pixels
* @format: DRM-style fourcc, see drm_fourcc.h for standard formats
* @fd: dma_buf fd for each plane
* @offset: location of first pixel to scan out, in bytes
* @pitch: stride (i.e. length of a scanline including padding) in bytes
* @n_planes: number of planes in buffer
* @acquire_fence: sync_fence fd which will clear when the buffer is
* ready for display, or <0 if the buffer is already ready
*/
struct adf_buffer_config {
__u32 overlay_engine;
__u32 w;
__u32 h;
__u32 format;
__s32 fd[ADF_MAX_PLANES];
__u32 offset[ADF_MAX_PLANES];
__u32 pitch[ADF_MAX_PLANES];
__u8 n_planes;
__s32 acquire_fence;
};
#define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
/**
* struct adf_post_config - request to flip to a new set of buffers
*
* This request is equivalent to &struct adf_post_config_v2 with
* @complete_fence_type = %ADF_COMPLETE_FENCE_RELEASE.
*
* @n_interfaces: number of interfaces targeted by the flip (input)
* @interfaces: ids of interfaces targeted by the flip (input)
* @n_bufs: number of buffers displayed (input)
* @bufs: description of buffers displayed (input)
* @custom_data_size: size of driver-private data (input)
* @custom_data: driver-private data (input)
* @complete_fence: sync_fence fd which will clear when this
* configuration has left the screen (output)
*/
struct adf_post_config {
size_t n_interfaces;
__u32 __user *interfaces;
size_t n_bufs;
struct adf_buffer_config __user *bufs;
size_t custom_data_size;
void __user *custom_data;
__s32 complete_fence;
};
/**
* struct adf_post_config_v2 - request to flip to a new set of buffers
*
* @n_interfaces: number of interfaces targeted by the flip (input)
* @interfaces: ids of interfaces targeted by the flip (input)
* @n_bufs: number of buffers displayed (input)
* @bufs: description of buffers displayed (input)
* @custom_data_size: size of driver-private data (input)
* @custom_data: driver-private data (input)
* @complete_fence_type: one of &enum adf_complete_fence_type describing what
* fence to return (input)
* @complete_fence: sync_fence fd which will fire at the time
* requested by @complete_fence_type (output)
*/
struct adf_post_config_v2 {
__u32 n_interfaces;
__u64 interfaces; /* __u32 * packed into __u64 */
__u32 n_bufs;
__u64 bufs; /* struct adf_buffer_config * packed into __u64 */
__u64 custom_data_size;
__u64 custom_data; /* void * packed into __u64 */
__s32 complete_fence;
__u8 complete_fence_type;
};
#define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
/**
* struct adf_simple_buffer_allocate - request to allocate a "simple" buffer
*
* @w: width of buffer in pixels (input)
* @h: height of buffer in pixels (input)
* @format: DRM-style fourcc (input)
*
* @fd: dma_buf fd (output)
* @offset: location of first pixel, in bytes (output)
* @pitch: length of a scanline including padding, in bytes (output)
*
* Simple buffers are analogous to DRM's "dumb" buffers. They have a single
* plane of linear RGB data which can be allocated and scanned out without
* any driver-private ioctls or data.
*
* @format must be a standard RGB format defined in drm_fourcc.h.
*
* ADF clients must NOT assume that an interface can scan out a simple buffer
* allocated by a different ADF interface, even if the two interfaces belong to
* the same ADF device.
*/
struct adf_simple_buffer_alloc {
__u16 w;
__u16 h;
__u32 format;
__s32 fd;
__u32 offset;
__u32 pitch;
};
/**
* struct adf_simple_post_config - request to flip to a single buffer without
* driver-private data
*
* This request is equivalent to &struct adf_simple_post_config_v2 with
* @complete_fence_type = %ADF_COMPLETE_FENCE_RELEASE.
*
* @buf: description of buffer displayed (input)
* @complete_fence: sync_fence fd which will clear when this buffer has left the
* screen (output)
*/
struct adf_simple_post_config {
struct adf_buffer_config buf;
__s32 complete_fence;
};
/**
* struct adf_simple_post_config_v2 - request to flip to a single buffer without
* driver-private data
*
* @buf: description of buffer displayed (input)
* @complete_fence_type: one of &enum adf_complete_fence_type describing what
* fence to return (input)
* @complete_fence: sync_fence fd which will fire at the time
* requested by @complete_fence_type (output)
*/
struct adf_simple_post_config_v2 {
struct adf_buffer_config buf;
__s32 complete_fence;
__u8 complete_fence_type;
};
/**
* struct adf_attachment_config - description of attachment between an overlay
* engine and an interface
*
* @overlay_engine: id of the overlay engine
* @interface: id of the interface
*/
struct adf_attachment_config {
__u32 overlay_engine;
__u32 interface;
};
/**
* struct adf_device_data - describes a display device
*
* @name: display device's name
* @n_attachments: the number of current attachments
* @attachments: list of current attachments
* @n_allowed_attachments: the number of allowed attachments
* @allowed_attachments: list of allowed attachments
* @custom_data_size: size of driver-private data
* @custom_data: driver-private data
*/
struct adf_device_data {
char name[ADF_NAME_LEN];
size_t n_attachments;
struct adf_attachment_config __user *attachments;
size_t n_allowed_attachments;
struct adf_attachment_config __user *allowed_attachments;
size_t custom_data_size;
void __user *custom_data;
};
#define ADF_MAX_ATTACHMENTS (4096 / sizeof(struct adf_attachment_config))
/**
* struct adf_device_data - describes a display interface
*
* @name: display interface's name
* @type: interface type (see enum @adf_interface_type)
* @id: which interface of type @type;
* e.g. interface DSI.1 -> @type=@ADF_INTF_TYPE_DSI, @id=1
* @flags: informational flags (bitmask of %ADF_INTF_FLAG_* values)
* @dpms_state: DPMS state (one of @DRM_MODE_DPMS_* defined in drm_mode.h)
* @hotplug_detect: whether a display is plugged in
* @width_mm: screen width in millimeters, or 0 if unknown
* @height_mm: screen height in millimeters, or 0 if unknown
* @current_mode: current display mode
* @n_available_modes: the number of hardware display modes
* @available_modes: list of hardware display modes
* @custom_data_size: size of driver-private data
* @custom_data: driver-private data
*/
struct adf_interface_data {
char name[ADF_NAME_LEN];
__u32 type;
__u32 id;
/* e.g. type=ADF_INTF_TYPE_DSI, id=1 => DSI.1 */
__u32 flags;
__u8 dpms_state;
__u8 hotplug_detect;
__u16 width_mm;
__u16 height_mm;
struct drm_mode_modeinfo current_mode;
size_t n_available_modes;
struct drm_mode_modeinfo __user *available_modes;
size_t custom_data_size;
void __user *custom_data;
};
#define ADF_MAX_MODES (4096 / sizeof(struct drm_mode_modeinfo))
/**
* struct adf_overlay_engine_data - describes an overlay engine
*
* @name: overlay engine's name
* @n_supported_formats: number of supported formats
* @supported_formats: list of supported formats
* @custom_data_size: size of driver-private data
* @custom_data: driver-private data
*/
struct adf_overlay_engine_data {
char name[ADF_NAME_LEN];
size_t n_supported_formats;
__u32 __user *supported_formats;
size_t custom_data_size;
void __user *custom_data;
};
#define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
#define ADF_IOCTL_TYPE 'D'
#define ADF_IOCTL_NR_CUSTOM 128
#define ADF_SET_EVENT _IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
#define ADF_BLANK _IOW(ADF_IOCTL_TYPE, 1, __u8)
#define ADF_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
#define ADF_SET_MODE _IOW(ADF_IOCTL_TYPE, 3, \
struct drm_mode_modeinfo)
#define ADF_GET_DEVICE_DATA _IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
#define ADF_GET_INTERFACE_DATA _IOR(ADF_IOCTL_TYPE, 5, \
struct adf_interface_data)
#define ADF_GET_OVERLAY_ENGINE_DATA \
_IOR(ADF_IOCTL_TYPE, 6, \
struct adf_overlay_engine_data)
#define ADF_SIMPLE_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 7, \
struct adf_simple_post_config)
#define ADF_SIMPLE_BUFFER_ALLOC _IOW(ADF_IOCTL_TYPE, 8, \
struct adf_simple_buffer_alloc)
#define ADF_ATTACH _IOW(ADF_IOCTL_TYPE, 9, \
struct adf_attachment_config)
#define ADF_DETACH _IOW(ADF_IOCTL_TYPE, 10, \
struct adf_attachment_config)
#define ADF_POST_CONFIG_V2 _IOW(ADF_IOCTL_TYPE, 11, \
struct adf_post_config_v2)
#define ADF_SIMPLE_POST_CONFIG_V2 \
_IOW(ADF_IOCTL_TYPE, 12, \
struct adf_simple_post_config_v2)
#endif /* _UAPI_VIDEO_ADF_H_ */

View file

@ -1,23 +0,0 @@
//
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
cc_test {
name: "adf-unit-tests",
srcs: ["adf_test.cpp"],
shared_libs: ["libsync"],
static_libs: ["libadf"],
cflags: ["-Werror"],
}

View file

@ -1,403 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <fcntl.h>
#include <adf/adf.h>
#include <gtest/gtest.h>
#include <sys/mman.h>
#include <sync/sync.h>
class AdfTest : public testing::Test {
public:
AdfTest() : intf_id(0), intf(-1), eng_id(0), eng(-1) { }
virtual void SetUp() {
int err = adf_device_open(dev_id, O_RDWR, &dev);
ASSERT_GE(err, 0) << "opening ADF device " << dev_id <<
" failed: " << strerror(-err);
err = adf_find_simple_post_configuration(&dev, fmt8888, n_fmt8888,
&intf_id, &eng_id);
ASSERT_GE(err, 0) << "finding ADF configuration failed: " <<
strerror(-err);
intf = adf_interface_open(&dev, intf_id, O_RDWR);
ASSERT_GE(intf, 0) << "opening ADF interface " << dev_id << "." <<
intf_id << " failed: " << strerror(-intf);
eng = adf_overlay_engine_open(&dev, eng_id, O_RDWR);
ASSERT_GE(eng, 0) << "opening ADF overlay engine " << dev_id << "." <<
eng_id << " failed: " << strerror(-eng);
}
virtual void TearDown() {
if (eng >= 0)
close(eng);
if (intf >= 0)
close(intf);
adf_device_close(&dev);
}
void get8888Format(uint32_t &fmt, char fmt_str[ADF_FORMAT_STR_SIZE]) {
adf_overlay_engine_data data;
int err = adf_get_overlay_engine_data(eng, &data);
ASSERT_GE(err, 0) << "getting ADF overlay engine data failed: " <<
strerror(-err);
for (size_t i = 0; i < data.n_supported_formats; i++) {
for (size_t j = 0; j < n_fmt8888; j++) {
if (data.supported_formats[i] == fmt8888[j]) {
fmt = data.supported_formats[i];
adf_format_str(fmt, fmt_str);
adf_free_overlay_engine_data(&data);
return;
}
}
}
adf_free_overlay_engine_data(&data);
FAIL(); /* this should never happen */
}
/* various helpers to call ADF and die on failure */
void getInterfaceData(adf_interface_data &data) {
int err = adf_get_interface_data(intf, &data);
ASSERT_GE(err, 0) << "getting ADF interface data failed: " <<
strerror(-err);
}
void getCurrentMode(uint32_t &w, uint32_t &h) {
adf_interface_data data;
ASSERT_NO_FATAL_FAILURE(getInterfaceData(data));
w = data.current_mode.hdisplay;
h = data.current_mode.vdisplay;
adf_free_interface_data(&data);
}
void blank(uint8_t mode) {
int err = adf_interface_blank(intf, mode);
ASSERT_FALSE(err < 0 && err != -EBUSY) <<
"unblanking interface failed: " << strerror(-err);
}
void attach() {
int err = adf_device_attach(&dev, eng_id, intf_id);
ASSERT_FALSE(err < 0 && err != -EALREADY) <<
"attaching overlay engine " << eng_id << " to interface " <<
intf_id << " failed: " << strerror(-err);
}
void detach() {
int err = adf_device_detach(&dev, eng_id, intf_id);
ASSERT_FALSE(err < 0 && err != -EINVAL) <<
"detaching overlay engine " << eng_id << " from interface " <<
intf_id << " failed: " << strerror(-err);
}
void readVsyncTimestamp(uint64_t &timestamp) {
adf_event *event;
int err = adf_read_event(intf, &event);
ASSERT_GE(err, 0) << "reading ADF event failed: " << strerror(-err);
ASSERT_EQ(ADF_EVENT_VSYNC, event->type);
ASSERT_EQ(sizeof(adf_vsync_event), event->length);
adf_vsync_event *vsync_event =
reinterpret_cast<adf_vsync_event *>(event);
timestamp = vsync_event->timestamp;
free(event);
}
void drawCheckerboard(uint32_t &w, uint32_t &h, uint32_t &format,
char format_str[ADF_FORMAT_STR_SIZE], int &buf_fd, uint32_t &offset,
uint32_t &pitch) {
ASSERT_NO_FATAL_FAILURE(getCurrentMode(w, h));
ASSERT_NO_FATAL_FAILURE(get8888Format(format, format_str));
buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, format, &offset,
&pitch);
ASSERT_GE(buf_fd, 0) << "allocating " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-buf_fd);
EXPECT_GE(pitch, w * 4);
void *mapped = mmap(NULL, pitch * h, PROT_WRITE, MAP_SHARED, buf_fd,
offset);
ASSERT_NE(mapped, MAP_FAILED) << "mapping " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-errno);
uint8_t *buf8 = static_cast<uint8_t *>(mapped);
for (uint32_t y = 0; y < h / 2; y++) {
uint32_t *scanline = reinterpret_cast<uint32_t *>(buf8 + y * pitch);
for (uint32_t x = 0; x < w / 2; x++)
scanline[x] = 0xFF0000FF;
for (uint32_t x = w / 2; x < w; x++)
scanline[x] = 0xFF00FFFF;
}
for (uint32_t y = h / 2; y < h; y++) {
uint32_t *scanline = reinterpret_cast<uint32_t *>(buf8 + y * pitch);
for (uint32_t x = 0; x < w / 2; x++)
scanline[x] = 0xFFFF00FF;
for (uint32_t x = w / 2; x < w; x++)
scanline[x] = 0xFFFFFFFF;
}
munmap(mapped, pitch * h);
}
protected:
adf_device dev;
adf_id_t intf_id;
int intf;
adf_id_t eng_id;
int eng;
private:
const static adf_id_t dev_id;
const static __u32 fmt8888[];
const static size_t n_fmt8888;
};
const adf_id_t AdfTest::dev_id = 0;
const __u32 AdfTest::fmt8888[] = {
DRM_FORMAT_XRGB8888,
DRM_FORMAT_XBGR8888,
DRM_FORMAT_RGBX8888,
DRM_FORMAT_BGRX8888,
DRM_FORMAT_ARGB8888,
DRM_FORMAT_ABGR8888,
DRM_FORMAT_RGBA8888,
DRM_FORMAT_BGRA8888
};
const size_t AdfTest::n_fmt8888 = sizeof(fmt8888) / sizeof(fmt8888[0]);
TEST(adf, devices) {
adf_id_t *devs = nullptr;
ssize_t n_devs = adf_devices(&devs);
free(devs);
ASSERT_GE(n_devs, 0) << "enumerating ADF devices failed: " <<
strerror(-n_devs);
ASSERT_TRUE(devs != NULL);
}
TEST_F(AdfTest, device_data) {
adf_device_data data;
int err = adf_get_device_data(&dev, &data);
ASSERT_GE(err, 0) << "getting ADF device data failed: " << strerror(-err);
EXPECT_LT(data.n_attachments, ADF_MAX_ATTACHMENTS);
EXPECT_GT(data.n_allowed_attachments, 0U);
EXPECT_LT(data.n_allowed_attachments, ADF_MAX_ATTACHMENTS);
EXPECT_LT(data.custom_data_size, (size_t)ADF_MAX_CUSTOM_DATA_SIZE);
adf_free_device_data(&data);
}
TEST_F(AdfTest, interface_data) {
adf_interface_data data;
ASSERT_NO_FATAL_FAILURE(getInterfaceData(data));
EXPECT_LT(data.type, ADF_INTF_TYPE_MAX);
EXPECT_LE(data.dpms_state, DRM_MODE_DPMS_OFF);
EXPECT_EQ(1, data.hotplug_detect);
EXPECT_GT(data.n_available_modes, 0U);
EXPECT_LT(data.custom_data_size, (size_t)ADF_MAX_CUSTOM_DATA_SIZE);
adf_free_interface_data(&data);
}
TEST_F(AdfTest, overlay_engine_data) {
adf_overlay_engine_data data;
int err = adf_get_overlay_engine_data(eng, &data);
ASSERT_GE(err, 0) << "getting ADF overlay engine failed: " <<
strerror(-err);
EXPECT_GT(data.n_supported_formats, 0U);
EXPECT_LT(data.n_supported_formats, ADF_MAX_SUPPORTED_FORMATS);
EXPECT_LT(data.custom_data_size, (size_t)ADF_MAX_CUSTOM_DATA_SIZE);
adf_free_overlay_engine_data(&data);
}
TEST_F(AdfTest, blank) {
int err = adf_interface_blank(intf, (uint8_t)-1);
EXPECT_EQ(-EINVAL, err) << "setting bogus DPMS mode should have failed";
err = adf_interface_blank(eng, DRM_MODE_DPMS_OFF);
EXPECT_EQ(-EINVAL, err) << "blanking overlay engine should have failed";
ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_OFF));
err = adf_interface_blank(intf, DRM_MODE_DPMS_OFF);
EXPECT_EQ(-EBUSY, err) << "blanking interface twice should have failed";
ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
err = adf_interface_blank(intf, DRM_MODE_DPMS_ON);
EXPECT_EQ(-EBUSY, err) << "unblanking interface twice should have failed";
adf_interface_data data;
ASSERT_NO_FATAL_FAILURE(getInterfaceData(data));
EXPECT_EQ(DRM_MODE_DPMS_ON, data.dpms_state);
adf_free_interface_data(&data);
}
TEST_F(AdfTest, event) {
int err = adf_set_event(intf, ADF_EVENT_TYPE_MAX, true);
EXPECT_EQ(-EINVAL, err) << "enabling bogus ADF event should have failed";
err = adf_set_event(intf, ADF_EVENT_TYPE_MAX, false);
EXPECT_EQ(-EINVAL, err) << "disabling bogus ADF event should have failed";
err = adf_set_event(intf, ADF_EVENT_VSYNC, true);
ASSERT_GE(err, 0) << "enabling vsync event failed: " << strerror(-err);
err = adf_set_event(intf, ADF_EVENT_VSYNC, true);
EXPECT_EQ(-EALREADY, err) <<
"enabling vsync event twice should have failed";
ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
uint64_t timestamp1, timestamp2;
ASSERT_NO_FATAL_FAILURE(readVsyncTimestamp(timestamp1));
ASSERT_NO_FATAL_FAILURE(readVsyncTimestamp(timestamp2));
EXPECT_GT(timestamp2, timestamp1);
err = adf_set_event(intf, ADF_EVENT_VSYNC, false);
EXPECT_GE(err, 0) << "disabling vsync event failed: " << strerror(-err);
err = adf_set_event(intf, ADF_EVENT_VSYNC, false);
EXPECT_EQ(-EALREADY, err) <<
"disabling vsync event twice should have failed";
}
TEST_F(AdfTest, attach) {
ASSERT_NO_FATAL_FAILURE(attach());
int err = adf_device_attach(&dev, eng_id, intf_id);
EXPECT_EQ(-EALREADY, err) << "attaching overlay engine " << eng_id <<
" to interface " << intf_id << " twice should have failed";
ASSERT_NO_FATAL_FAILURE(detach());
err = adf_device_detach(&dev, eng_id, intf_id);
EXPECT_EQ(-EINVAL, err) << "detaching overlay engine " << eng_id <<
" from interface " << intf_id << " twice should have failed";
err = adf_device_attach(&dev, eng_id, ADF_MAX_INTERFACES);
EXPECT_EQ(-EINVAL, err) << "attaching overlay engine " << eng_id <<
" to bogus interface should have failed";
err = adf_device_detach(&dev, eng_id, ADF_MAX_INTERFACES);
EXPECT_EQ(-EINVAL, err) << "detaching overlay engine " << eng_id <<
" from bogus interface should have failed";
}
TEST_F(AdfTest, simple_buffer_alloc) {
uint32_t w = 0, h = 0;
ASSERT_NO_FATAL_FAILURE(getCurrentMode(w, h));
uint32_t format;
char format_str[ADF_FORMAT_STR_SIZE];
ASSERT_NO_FATAL_FAILURE(get8888Format(format, format_str));
uint32_t offset;
uint32_t pitch;
int buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, format, &offset,
&pitch);
EXPECT_GE(buf_fd, 0) << "allocating " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-buf_fd);
EXPECT_GE(pitch, w * 4);
close(buf_fd);
buf_fd = adf_interface_simple_buffer_alloc(intf, w, h, 0xDEADBEEF, &offset,
&pitch);
/* n.b.: ADF only allows simple buffers with built-in RGB formats,
so this should fail even if a driver supports custom format 0xDEADBEEF */
EXPECT_EQ(-EINVAL, buf_fd) <<
"allocating buffer with bogus format should have failed";
}
TEST_F(AdfTest, simple_buffer) {
int buf_fd;
uint32_t w, h, format, offset, pitch;
char format_str[ADF_FORMAT_STR_SIZE];
ASSERT_NO_FATAL_FAILURE(drawCheckerboard(w, h, format, format_str,
buf_fd, offset, pitch));
ASSERT_NO_FATAL_FAILURE(attach());
ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
int release_fence = adf_interface_simple_post(intf, eng_id, w, h, format,
buf_fd, offset, pitch, -1);
close(buf_fd);
ASSERT_GE(release_fence, 0) << "posting " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-release_fence);
close(release_fence);
}
TEST_F(AdfTest, simple_buffer_v2) {
int buf_fd;
uint32_t w, h, format, offset, pitch;
char format_str[ADF_FORMAT_STR_SIZE];
ASSERT_NO_FATAL_FAILURE(drawCheckerboard(w, h, format, format_str,
buf_fd, offset, pitch));
ASSERT_NO_FATAL_FAILURE(attach());
ASSERT_NO_FATAL_FAILURE(blank(DRM_MODE_DPMS_ON));
int config_1_release;
int err = adf_interface_simple_post_v2(intf, eng_id, w, h,
format, buf_fd, offset, pitch, -1, ADF_COMPLETE_FENCE_RELEASE,
&config_1_release);
if (err == -ENOTTY) {
GTEST_LOG_(INFO) << "ADF_SIMPLE_POST_CONFIG_V2 not supported on this kernel";
return;
}
ASSERT_GE(err, 0) << "posting " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-err);
err = sync_wait(config_1_release, 1000);
ASSERT_EQ(-1, err) <<
"waiting for config 1's release fence should not have suceeded";
ASSERT_EQ(ETIME, errno) <<
"config 1's release fence should have timed out, but failed instead: " <<
strerror(errno);
int config_2_present;
err = adf_interface_simple_post_v2(intf, eng_id, w, h,
format, buf_fd, offset, pitch, -1, ADF_COMPLETE_FENCE_PRESENT,
&config_2_present);
ASSERT_GE(err, 0) << "posting " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-err);
err = sync_wait(config_2_present, 1000);
ASSERT_EQ(0, err) <<
"waiting for config 2's present fence failed: " << strerror(errno);
err = sync_wait(config_1_release, 0);
ASSERT_EQ(0, err) <<
"waiting for config 1's release fence failed: " << strerror(errno);
close(config_1_release);
close(config_2_present);
int config_3_no_fence;
err = adf_interface_simple_post_v2(intf, eng_id, w, h,
format, buf_fd, offset, pitch, -1, ADF_COMPLETE_FENCE_NONE,
&config_3_no_fence);
ASSERT_GE(err, 0) << "posting " << w << "x" << h << " " <<
format_str << " buffer failed: " << strerror(-err);
ASSERT_EQ(-1, config_3_no_fence) <<
"fence returned even though the fence type was ADF_COMPLETE_FENCE_NONE";
close(buf_fd);
}

View file

@ -1,29 +0,0 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_library_static {
name: "libadfhwc",
srcs: ["adfhwc.cpp"],
static_libs: [
"libadf",
"liblog",
"libutils",
],
cflags: [
"-DLOG_TAG=\"adfhwc\"",
"-Werror",
],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
}

View file

@ -1,376 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <fcntl.h>
#include <malloc.h>
#include <poll.h>
#include <pthread.h>
#include <sys/resource.h>
#include <log/log.h>
#include <utils/Vector.h>
#include <adf/adf.h>
#include <adfhwc/adfhwc.h>
struct adf_hwc_helper {
adf_hwc_event_callbacks const *event_cb;
void *event_cb_data;
pthread_t event_thread;
android::Vector<int> intf_fds;
android::Vector<drm_mode_modeinfo> display_configs;
};
template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
int adf_eventControl(struct adf_hwc_helper *dev, int disp, int event,
int enabled)
{
if (enabled != !!enabled)
return -EINVAL;
if ((size_t)disp >= dev->intf_fds.size())
return -EINVAL;
switch (event) {
case HWC_EVENT_VSYNC:
return adf_set_event(dev->intf_fds[disp], ADF_EVENT_VSYNC, enabled);
}
return -EINVAL;
}
static inline int32_t dpi(uint16_t res, uint16_t size_mm)
{
if (size_mm)
return 1000 * (res * 25.4f) / size_mm;
return 0;
}
int adf_blank(struct adf_hwc_helper *dev, int disp, int blank)
{
if ((size_t)disp >= dev->intf_fds.size())
return -EINVAL;
uint8_t dpms_mode = blank ? DRM_MODE_DPMS_OFF : DRM_MODE_DPMS_ON;
return adf_interface_blank(dev->intf_fds[disp], dpms_mode);
}
int adf_query_display_types_supported(struct adf_hwc_helper *dev, int *value)
{
*value = 0;
if (dev->intf_fds.size() > 0)
*value |= HWC_DISPLAY_PRIMARY_BIT;
if (dev->intf_fds.size() > 1)
*value |= HWC_DISPLAY_EXTERNAL_BIT;
return 0;
}
int adf_getDisplayConfigs(struct adf_hwc_helper *dev, int disp,
uint32_t *configs, size_t *numConfigs)
{
if ((size_t)disp >= dev->intf_fds.size())
return -EINVAL;
adf_interface_data data;
int err = adf_get_interface_data(dev->intf_fds[disp], &data);
if (err < 0) {
ALOGE("failed to get ADF interface data: %s", strerror(err));
return err;
}
if (!data.hotplug_detect)
return -ENODEV;
android::Vector<drm_mode_modeinfo *> unique_configs;
unique_configs.push_back(&data.current_mode);
for (size_t i = 0; i < data.n_available_modes; i++)
if (memcmp(&data.available_modes[i], &data.current_mode,
sizeof(data.current_mode)))
unique_configs.push_back(&data.available_modes[i]);
for (size_t i = 0; i < min(*numConfigs, unique_configs.size()); i++) {
configs[i] = dev->display_configs.size();
dev->display_configs.push_back(*unique_configs[i]);
}
*numConfigs = unique_configs.size();
adf_free_interface_data(&data);
return 0;
}
static int32_t adf_display_attribute(const adf_interface_data &data,
const drm_mode_modeinfo &mode, const uint32_t attribute)
{
switch (attribute) {
case HWC_DISPLAY_VSYNC_PERIOD:
if (mode.vrefresh)
return 1000000000 / mode.vrefresh;
return 0;
case HWC_DISPLAY_WIDTH:
return mode.hdisplay;
case HWC_DISPLAY_HEIGHT:
return mode.vdisplay;
case HWC_DISPLAY_DPI_X:
return dpi(mode.hdisplay, data.width_mm);
case HWC_DISPLAY_DPI_Y:
return dpi(mode.vdisplay, data.height_mm);
default:
ALOGE("unknown display attribute %u", attribute);
return -EINVAL;
}
}
int adf_getDisplayAttributes(struct adf_hwc_helper *dev, int disp,
uint32_t config, const uint32_t *attributes, int32_t *values)
{
if ((size_t)disp >= dev->intf_fds.size())
return -EINVAL;
if (config >= dev->display_configs.size())
return -EINVAL;
adf_interface_data data;
int err = adf_get_interface_data(dev->intf_fds[disp], &data);
if (err < 0) {
ALOGE("failed to get ADF interface data: %s", strerror(err));
return err;
}
for (int i = 0; attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; i++)
values[i] = adf_display_attribute(data, dev->display_configs[config],
attributes[i]);
adf_free_interface_data(&data);
return 0;
}
static int32_t adf_display_attribute_hwc2(const adf_interface_data &data,
const drm_mode_modeinfo &mode, const uint32_t attribute)
{
switch (attribute) {
case HWC2_ATTRIBUTE_VSYNC_PERIOD:
if (mode.vrefresh)
return 1000000000 / mode.vrefresh;
return 0;
case HWC2_ATTRIBUTE_WIDTH:
return mode.hdisplay;
case HWC2_ATTRIBUTE_HEIGHT:
return mode.vdisplay;
case HWC2_ATTRIBUTE_DPI_X:
return dpi(mode.hdisplay, data.width_mm);
case HWC2_ATTRIBUTE_DPI_Y:
return dpi(mode.vdisplay, data.height_mm);
default:
ALOGE("unknown display attribute %u", attribute);
return -EINVAL;
}
}
int adf_getDisplayAttributes_hwc2(struct adf_hwc_helper *dev, int disp,
uint32_t config, const uint32_t *attributes, int32_t *values)
{
if ((size_t)disp >= dev->intf_fds.size())
return -EINVAL;
if (config >= dev->display_configs.size())
return -EINVAL;
adf_interface_data data;
int err = adf_get_interface_data(dev->intf_fds[disp], &data);
if (err < 0) {
ALOGE("failed to get ADF interface data: %s", strerror(err));
return err;
}
for (int i = 0; attributes[i] != HWC2_ATTRIBUTE_INVALID; i++)
values[i] = adf_display_attribute_hwc2(data,
dev->display_configs[config], attributes[i]);
adf_free_interface_data(&data);
return 0;
}
int adf_set_active_config_hwc2(struct adf_hwc_helper *dev, int disp,
uint32_t config)
{
if ((size_t)disp >= dev->intf_fds.size())
return -EINVAL;
if (config >= dev->display_configs.size())
return -EINVAL;
struct drm_mode_modeinfo mode = dev->display_configs[config];
return adf_interface_set_mode(dev->intf_fds[disp], &mode);
}
static void handle_adf_event(struct adf_hwc_helper *dev, int disp)
{
adf_event *event;
int err = adf_read_event(dev->intf_fds[disp], &event);
if (err < 0) {
ALOGE("error reading event from display %d: %s", disp, strerror(err));
return;
}
void *vsync_temp;
adf_vsync_event *vsync;
adf_hotplug_event *hotplug;
switch (event->type) {
case ADF_EVENT_VSYNC:
vsync_temp = event;
vsync = static_cast<adf_vsync_event *>(vsync_temp);
// casting directly to adf_vsync_event * makes g++ warn about
// potential alignment issues that don't apply here
dev->event_cb->vsync(dev->event_cb_data, disp, vsync->timestamp);
break;
case ADF_EVENT_HOTPLUG:
hotplug = reinterpret_cast<adf_hotplug_event *>(event);
dev->event_cb->hotplug(dev->event_cb_data, disp, hotplug->connected);
break;
default:
if (event->type < ADF_EVENT_DEVICE_CUSTOM)
ALOGW("unrecognized event type %u", event->type);
else if (!dev->event_cb || !dev->event_cb->custom_event)
ALOGW("unhandled event type %u", event->type);
else
dev->event_cb->custom_event(dev->event_cb_data, disp, event);
}
free(event);
}
static void *adf_event_thread(void *data)
{
adf_hwc_helper *dev = static_cast<adf_hwc_helper *>(data);
setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
struct sigaction action = { };
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
action.sa_handler = [](int) { pthread_exit(0); };
if (sigaction(SIGUSR2, &action, NULL) < 0) {
ALOGE("failed to set thread exit action %s", strerror(errno));
return NULL;
}
sigset_t signal_set;
sigemptyset(&signal_set);
sigaddset(&signal_set, SIGUSR2);
pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
pollfd fds[dev->intf_fds.size()];
for (size_t i = 0; i < dev->intf_fds.size(); i++) {
fds[i].fd = dev->intf_fds[i];
fds[i].events = POLLIN | POLLPRI;
}
while (true) {
if (TEMP_FAILURE_RETRY(poll(fds, dev->intf_fds.size(), -1)) < 0) {
ALOGE("error in event thread: %s", strerror(errno));
break;
}
for (size_t i = 0; i < dev->intf_fds.size(); i++)
if (fds[i].revents & (POLLIN | POLLPRI))
handle_adf_event(dev, i);
}
return NULL;
}
int adf_hwc_open(int *intf_fds, size_t n_intfs,
const struct adf_hwc_event_callbacks *event_cb, void *event_cb_data,
struct adf_hwc_helper **dev)
{
if (!n_intfs)
return -EINVAL;
adf_hwc_helper *dev_ret = new adf_hwc_helper;
dev_ret->event_cb = event_cb;
dev_ret->event_cb_data = event_cb_data;
int ret;
for (size_t i = 0; i < n_intfs; i++) {
int dup_intf_fd = dup(intf_fds[i]);
if (dup_intf_fd < 0) {
ALOGE("failed to dup interface fd: %s", strerror(errno));
ret = -errno;
goto err;
}
dev_ret->intf_fds.push_back(dup_intf_fd);
ret = adf_set_event(dup_intf_fd, ADF_EVENT_HOTPLUG, 1);
if (ret < 0 && ret != -EINVAL) {
ALOGE("failed to enable hotplug event on display %zu: %s",
i, strerror(errno));
goto err;
}
}
sigset_t signal_set;
sigemptyset(&signal_set);
sigaddset(&signal_set, SIGUSR2);
pthread_sigmask(SIG_BLOCK, &signal_set, NULL);
ret = pthread_create(&dev_ret->event_thread, NULL, adf_event_thread,
dev_ret);
if (ret) {
ALOGE("failed to create event thread: %s", strerror(ret));
goto err;
}
*dev = dev_ret;
return 0;
err:
for (size_t i = 0; i < dev_ret->intf_fds.size(); i++)
close(dev_ret->intf_fds[i]);
delete dev_ret;
return ret;
}
void adf_hwc_close(struct adf_hwc_helper *dev)
{
pthread_kill(dev->event_thread, SIGUSR2);
pthread_join(dev->event_thread, NULL);
for (size_t i = 0; i < dev->intf_fds.size(); i++)
close(dev->intf_fds[i]);
delete dev;
}

View file

@ -1,140 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBADFHWC_ADFHWC_H_
#define _LIBADFHWC_ADFHWC_H_
#include <stdbool.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <video/adf.h>
#include <hardware/hwcomposer.h>
#include <hardware/hwcomposer2.h>
struct adf_hwc_helper;
struct adf_hwc_event_callbacks {
/**
* Called on vsync (required)
*/
void (*vsync)(void *data, int disp, uint64_t timestamp);
/**
* Called on hotplug (required)
*/
void (*hotplug)(void *data, int disp, bool connected);
/**
* Called on hardware-custom ADF events (optional)
*/
void (*custom_event)(void *data, int disp, struct adf_event *event);
};
/**
* Converts HAL pixel formats to equivalent ADF/DRM format FourCCs.
*/
static inline uint32_t adf_fourcc_for_hal_pixel_format(int format)
{
switch (format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
return DRM_FORMAT_RGBA8888;
case HAL_PIXEL_FORMAT_RGBX_8888:
return DRM_FORMAT_RGBX8888;
case HAL_PIXEL_FORMAT_RGB_888:
return DRM_FORMAT_RGB888;
case HAL_PIXEL_FORMAT_RGB_565:
return DRM_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_BGRA_8888:
return DRM_FORMAT_BGRA8888;
case HAL_PIXEL_FORMAT_YV12:
return DRM_FORMAT_YVU420;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
return DRM_FORMAT_NV16;
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
return DRM_FORMAT_NV21;
case HAL_PIXEL_FORMAT_YCbCr_422_I:
return DRM_FORMAT_YUYV;
default:
return 0;
}
}
/**
* Converts HAL display types to equivalent ADF interface flags.
*/
static inline uint32_t adf_hwc_interface_flag_for_disp(int disp)
{
switch (disp) {
case HWC_DISPLAY_PRIMARY:
return ADF_INTF_FLAG_PRIMARY;
case HWC_DISPLAY_EXTERNAL:
return ADF_INTF_FLAG_EXTERNAL;
default:
return 0;
}
}
__BEGIN_DECLS
/**
* Create a HWC helper for the specified ADF interfaces.
*
* intf_fds must be indexed by HWC display type: e.g.,
* intf_fds[HWC_DISPLAY_PRIMARY] is the fd for the primary display
* interface. n_intfs must be >= 1.
*
* The caller retains ownership of the fds in intf_fds and must close()
* them when they are no longer needed.
*
* On error, returns -errno.
*/
int adf_hwc_open(int *intf_fds, size_t n_intfs,
const struct adf_hwc_event_callbacks *event_cb, void *event_cb_data,
struct adf_hwc_helper **dev);
/**
* Destroys a HWC helper.
*/
void adf_hwc_close(struct adf_hwc_helper *dev);
/**
* Generic implementations of common HWC ops.
*
* The HWC should not point its ops directly at these helpers. Instead, the HWC
* should provide stub ops which call these helpers after converting the
* hwc_composer_device_1* to a struct adf_hwc_helper*.
*/
int adf_eventControl(struct adf_hwc_helper *dev, int disp, int event,
int enabled);
int adf_blank(struct adf_hwc_helper *dev, int disp, int blank);
int adf_query_display_types_supported(struct adf_hwc_helper *dev, int *value);
int adf_getDisplayConfigs(struct adf_hwc_helper *dev, int disp,
uint32_t *configs, size_t *numConfigs);
int adf_getDisplayAttributes(struct adf_hwc_helper *dev, int disp,
uint32_t config, const uint32_t *attributes, int32_t *values);
/**
* Generic implementation of common HWC2 functions.
*
* The HWC2 should not return these functions directly through getFunction.
* Instead, the HWC2 should return stub functions which call these helpers.
*/
int adf_getDisplayAttributes_hwc2(struct adf_hwc_helper *dev, int disp,
uint32_t config, const uint32_t *attributes, int32_t *values);
int adf_set_active_config_hwc2(struct adf_hwc_helper *dev, int disp,
uint32_t config);
__END_DECLS
#endif /* _LIBADFHWC_ADFHWC_H_ */