18c2ecf20Sopenharmony_ci#ifndef __ION_UTILS_H
28c2ecf20Sopenharmony_ci#define __ION_UTILS_H
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "ion.h"
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#define SOCKET_NAME "ion_socket"
78c2ecf20Sopenharmony_ci#define ION_DEVICE "/dev/ion"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define ION_BUFFER_LEN	4096
108c2ecf20Sopenharmony_ci#define MAX_HEAP_COUNT	ION_HEAP_TYPE_CUSTOM
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct socket_info {
138c2ecf20Sopenharmony_ci	int sockfd;
148c2ecf20Sopenharmony_ci	int datafd;
158c2ecf20Sopenharmony_ci	unsigned long buflen;
168c2ecf20Sopenharmony_ci};
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct ion_buffer_info {
198c2ecf20Sopenharmony_ci	int ionfd;
208c2ecf20Sopenharmony_ci	int buffd;
218c2ecf20Sopenharmony_ci	unsigned int heap_type;
228c2ecf20Sopenharmony_ci	unsigned int flag_type;
238c2ecf20Sopenharmony_ci	unsigned long heap_size;
248c2ecf20Sopenharmony_ci	unsigned long buflen;
258c2ecf20Sopenharmony_ci	unsigned char *buffer;
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* This is used to fill the data into the mapped buffer */
308c2ecf20Sopenharmony_civoid write_buffer(void *buffer, unsigned long len);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* This is used to read the data from the exported buffer */
338c2ecf20Sopenharmony_civoid read_buffer(void *buffer, unsigned long len);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* This is used to create an ION buffer FD for the kernel buffer
368c2ecf20Sopenharmony_ci * So you can export this same buffer to others in the form of FD
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ciint ion_export_buffer_fd(struct ion_buffer_info *ion_info);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* This is used to import or map an exported FD.
418c2ecf20Sopenharmony_ci * So we point to same buffer without making a copy. Hence zero-copy.
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ciint ion_import_buffer_fd(struct ion_buffer_info *ion_info);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* This is used to close all references for the ION client */
468c2ecf20Sopenharmony_civoid ion_close_buffer_fd(struct ion_buffer_info *ion_info);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* This is used to send FD to another process using socket IPC */
498c2ecf20Sopenharmony_ciint socket_send_fd(struct socket_info *skinfo);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* This is used to receive FD from another process using socket IPC */
528c2ecf20Sopenharmony_ciint socket_receive_fd(struct socket_info *skinfo);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#endif
56