#ifndef __LOCAL_POC_H__
#define __LOCAL_POC_H__

#define FASTRPC_INIT_CREATE 1
#define remote_arg_t union remote_arg
#define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke)
#define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd)
#define ADSP_MMAP_ADD_PAGES 0x1000
#define FASTRPC_IOCTL_MMAP _IOWR('R', 2, struct fastrpc_ioctl_mmap)
#define FASTRPC_IOCTL_INIT _IOWR('R', 6, struct fastrpc_ioctl_init)
#define FASTRPC_IOCTL_GETINFO _IOWR('R', 8, uint32_t)
#define FASTRPC_IOCTL_INIT_ATTRS _IOWR('R', 10, struct fastrpc_ioctl_init_attrs)
#define FASTRPC_IOCTL_MUNMAP_FD _IOWR('R', 13, struct fastrpc_ioctl_munmap_fd)
#define ION_HEAP(bit) (1 << (bit))
#define ION_BIT(nr) (1UL << (nr))
#define ION_FLAG_CP_TOUCH ION_BIT(17)
#define ION_FLAG_CP_BITSTREAM ION_BIT(18)
#define ION_FLAG_CP_PIXEL ION_BIT(19)
#define ION_FLAG_CP_NON_PIXEL ION_BIT(20)
#define ION_FLAG_CP_CAMERA ION_BIT(21)
#define ION_FLAG_CP_HLOS ION_BIT(22)
#define ION_FLAG_CP_HLOS_FREE ION_BIT(23)
#define ION_FLAG_CP_SEC_DISPLAY ION_BIT(25)
#define ION_FLAG_CP_APP ION_BIT(26)
#define ION_FLAG_CP_CAMERA_PREVIEW ION_BIT(27)
#define ION_IOC_MAGIC 'I'
#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, struct ion_allocation_data)
#define ION_FLAG_SECURE ION_BIT(ION_HEAP_ID_RESERVED)

struct remote_buf {
  void *pv;
  size_t len;
};

struct remote_dma_handle {
  int fd;
  uint32_t offset;
};

union remote_arg {
  struct remote_buf buf;
  struct remote_dma_handle dma;
  uint32_t h;
};

struct fastrpc_ioctl_invoke {
  uint32_t handle;
  uint32_t sc;
  remote_arg_t *pra;
};

struct fastrpc_ioctl_invoke_fd {
  struct fastrpc_ioctl_invoke inv;
  int *fds;
};

struct fastrpc_ioctl_mmap {
  int fd;                 /* ion fd */
  uint32_t flags;         /* flags for dsp to map with */
  unsigned long vaddrin;  /* optional virtual address */
  size_t size;            /* size */
  unsigned long vaddrout; /* dsps virtual address */
};

struct fastrpc_ioctl_init {
  uint32_t flags;
  void *file;
  uint32_t filelen;
  int32_t filefd;
  void *mem;
  uint32_t memlen;
  int32_t memfd;
};

struct fastrpc_ioctl_init_attrs {
  struct fastrpc_ioctl_init init;
  int attrs;
  unsigned int siglen;
};


struct fastrpc_ioctl_munmap_fd {
  int fd;
  uint32_t flags;
  unsigned long va;
  ssize_t len;
};

enum ion_heap_ids {
  INVALID_HEAP_ID = -1,
  ION_CP_MM_HEAP_ID = 8,
  ION_SECURE_HEAP_ID = 9,
  ION_SECURE_DISPLAY_HEAP_ID = 10,
  ION_CP_MFC_HEAP_ID = 12,
  ION_SPSS_HEAP_ID = 13,   /* Secure Processor ION heap */
  ION_CP_WB_HEAP_ID = 16,  /* 8660 only */
  ION_CAMERA_HEAP_ID = 20, /* 8660 only */
  ION_SYSTEM_CONTIG_HEAP_ID = 21,
  ION_ADSP_HEAP_ID = 22,
  ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */
  ION_SF_HEAP_ID = 24,
  ION_SYSTEM_HEAP_ID = 25,
  ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */
  ION_QSECOM_HEAP_ID = 27,
  ION_AUDIO_HEAP_ID = 28,

  ION_MM_FIRMWARE_HEAP_ID = 29,
  ION_GOOGLE_HEAP_ID = 30,

  ION_HEAP_ID_RESERVED = 31 /**
     * Bit reserved for ION_FLAG_SECURE flag
     */
};

struct ion_allocation_data {
  uint64_t len;
  uint32_t heap_id_mask;
  uint32_t flags;
  uint32_t fd;
  uint32_t unused;
};

#endif
