1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _LIBADF_ADF_H_ 18 #define _LIBADF_ADF_H_ 19 20 #include <stdint.h> 21 #include <stdbool.h> 22 #include <sys/cdefs.h> 23 #include <sys/types.h> 24 #include <video/adf.h> 25 26 typedef __u32 adf_id_t; 27 28 struct adf_device { 29 adf_id_t id; 30 int fd; 31 }; 32 33 __BEGIN_DECLS 34 35 /** 36 * Enumerates all ADF devices. 37 * 38 * Returns the number of ADF devices, and sets ids to a list of device IDs. 39 * The caller must free() the returned list of device IDs. 40 * 41 * On error, returns -errno. 42 */ 43 ssize_t adf_devices(adf_id_t **ids); 44 45 /** 46 * Opens an ADF device. 47 * 48 * On error, returns -errno. 49 */ 50 int adf_device_open(adf_id_t id, int flags, struct adf_device *dev); 51 /** 52 * Closes an ADF device. 53 */ 54 void adf_device_close(struct adf_device *dev); 55 /** 56 * Reads the ADF device data. 57 * 58 * adf_get_device_data() allocates buffers inside data, which the caller 59 * must free by calling adf_free_device_data(). On error, returns -errno. 60 */ 61 int adf_get_device_data(struct adf_device *dev, struct adf_device_data *data); 62 /** 63 * Frees the device data returned by adf_get_device_data(). 64 */ 65 void adf_free_device_data(struct adf_device_data *data); 66 67 /** 68 * Atomically posts a new display configuration to the specified interfaces. 69 * 70 * Returns a sync fence fd that will fire when the configuration is removed 71 * from the screen. On error, returns -errno. 72 */ 73 int adf_device_post(struct adf_device *dev, 74 adf_id_t *interfaces, size_t n_interfaces, 75 struct adf_buffer_config *bufs, size_t n_bufs, 76 void *custom_data, size_t custom_data_size); 77 /** 78 * Attaches the specified interface and overlay engine. 79 */ 80 int adf_device_attach(struct adf_device *dev, adf_id_t overlay_engine, 81 adf_id_t interface); 82 /** 83 * Detaches the specified interface and overlay engine. 84 */ 85 int adf_device_detach(struct adf_device *dev, adf_id_t overlay_engine, 86 adf_id_t interface); 87 88 /** 89 * Enumerates all interfaces belonging to an ADF device. 90 * 91 * The caller must free() the returned list of interface IDs. 92 */ 93 ssize_t adf_interfaces(struct adf_device *dev, adf_id_t **interfaces); 94 95 /** 96 * Enumerates all interfaces which can be attached to the specified overlay 97 * engine. 98 * 99 * The caller must free() the returned list of interface IDs. 100 */ 101 ssize_t adf_interfaces_for_overlay_engine(struct adf_device *dev, 102 adf_id_t overlay_engine, adf_id_t **interfaces); 103 /** 104 * Filters a list of interfaces by type. 105 * 106 * Returns the number of matching interfaces, and sets out to a list of matching 107 * interface IDs. The caller must free() the returned list of interface IDs. 108 * 109 * On error, returns -errno. 110 */ 111 ssize_t adf_interfaces_filter_by_type(struct adf_device *dev, 112 enum adf_interface_type type, 113 adf_id_t *in, size_t n_in, adf_id_t **out); 114 /** 115 * Filters a list of interfaces by flag. 116 * 117 * The caller must free() the returned list of interface IDs. 118 */ 119 ssize_t adf_interfaces_filter_by_flag(struct adf_device *dev, __u32 flag, 120 adf_id_t *in, size_t n_in, adf_id_t **out); 121 122 /** 123 * Opens an ADF interface. 124 * 125 * Returns a file descriptor. The caller must close() the fd when done. 126 * On error, returns -errno. 127 */ 128 int adf_interface_open(struct adf_device *dev, adf_id_t id, int flags); 129 /** 130 * Reads the interface data. 131 * 132 * adf_get_interface_data() allocates buffers inside data, which the caller 133 * must free by calling adf_free_interface_data(). On error, returns -errno. 134 */ 135 int adf_get_interface_data(int fd, struct adf_interface_data *data); 136 /** 137 * Frees the interface data returned by adf_get_interface_data(). 138 */ 139 void adf_free_interface_data(struct adf_interface_data *data); 140 141 /** 142 * Sets the interface's DPMS mode. 143 */ 144 int adf_interface_blank(int fd, __u8 mode); 145 /** 146 * Sets the interface's display mode. 147 */ 148 int adf_interface_set_mode(int fd, struct drm_mode_modeinfo *mode); 149 /** 150 * Allocates a single-plane RGB buffer of the specified size and format. 151 * 152 * Returns a dma-buf fd. On error, returns -errno. 153 */ 154 int adf_interface_simple_buffer_alloc(int fd, __u32 w, __u32 h, 155 __u32 format, __u32 *offset, __u32 *pitch); 156 /** 157 * Posts a single-plane RGB buffer to the display using the specified 158 * overlay engine. 159 * 160 * Returns a sync fence fd that will fire when the buffer is removed 161 * from the screen. On error, returns -errno. 162 */ 163 int adf_interface_simple_post(int fd, adf_id_t overlay_engine, 164 __u32 w, __u32 h, __u32 format, int buf_fd, __u32 offset, 165 __u32 pitch, int acquire_fence); 166 167 /** 168 * Enumerates all overlay engines belonging to an ADF device. 169 * 170 * The caller must free() the returned list of overlay engine IDs. 171 */ 172 ssize_t adf_overlay_engines(struct adf_device *dev, adf_id_t **overlay_engines); 173 174 /** 175 * Enumerates all overlay engines which can be attached to the specified 176 * interface. 177 * 178 * The caller must free() the returned list of overlay engine IDs. 179 */ 180 ssize_t adf_overlay_engines_for_interface(struct adf_device *dev, 181 adf_id_t interface, adf_id_t **overlay_engines); 182 /** 183 * Filters a list of overlay engines by supported buffer format. 184 * 185 * Returns the overlay engines which support at least one of the specified 186 * formats. The caller must free() the returned list of overlay engine IDs. 187 */ 188 ssize_t adf_overlay_engines_filter_by_format(struct adf_device *dev, 189 const __u32 *formats, size_t n_formats, adf_id_t *in, size_t n_in, 190 adf_id_t **out); 191 192 /** 193 * Opens an ADF overlay engine. 194 * 195 * Returns a file descriptor. The caller must close() the fd when done. 196 * On error, returns -errno. 197 */ 198 int adf_overlay_engine_open(struct adf_device *dev, adf_id_t id, int flags); 199 /** 200 * Reads the overlay engine data. 201 * 202 * adf_get_overlay_engine_data() allocates buffers inside data, which the caller 203 * must free by calling adf_free_overlay_engine_data(). On error, returns 204 * -errno. 205 */ 206 int adf_get_overlay_engine_data(int fd, struct adf_overlay_engine_data *data); 207 /** 208 * Frees the overlay engine data returned by adf_get_overlay_engine_data(). 209 */ 210 void adf_free_overlay_engine_data(struct adf_overlay_engine_data *data); 211 212 /** 213 * Returns whether the overlay engine supports the specified format. 214 */ 215 bool adf_overlay_engine_supports_format(int fd, __u32 format); 216 217 /** 218 * Subscribes or unsubscribes from the specified hardware event. 219 */ 220 int adf_set_event(int fd, enum adf_event_type type, bool enabled); 221 /** 222 * Reads one event from the fd, blocking if needed. 223 * 224 * The caller must free() the returned buffer. On error, returns -errno. 225 */ 226 int adf_read_event(int fd, struct adf_event **event); 227 228 #define ADF_FORMAT_STR_SIZE 5 229 /** 230 * Converts an ADF/DRM fourcc format to its string representation. 231 */ 232 void adf_format_str(__u32 format, char buf[ADF_FORMAT_STR_SIZE]); 233 234 /** 235 * Finds an appropriate interface and overlay engine for a simple post. 236 * 237 * Specifically, finds the primary interface, and an overlay engine 238 * that can be attached to the primary interface and supports one of the 239 * specified formats. The caller may pass a NULL formats list, to indicate that 240 * any RGB format is acceptable. 241 * 242 * On error, returns -errno. 243 */ 244 int adf_find_simple_post_configuration(struct adf_device *dev, 245 const __u32 *formats, size_t n_formats, 246 adf_id_t *interface, adf_id_t *overlay_engine); 247 248 __END_DECLS 249 250 #endif /* _LIBADF_ADF_H_ */ 251