#if !defined(__RPI_VIDEOCORE_H__)
#define __RPI_VIDEOCORE_H__

#include <stdint.h>

#include "../common.h"

// Videocore mailbox memory allocation flags, see:
//     https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
typedef enum {
  MEM_FLAG_DISCARDABLE = 1 << 0,    // can be resized to 0 at any time. Use for cached data
  MEM_FLAG_NORMAL = 0 << 2,         // normal allocating alias. Don't use from ARM
  MEM_FLAG_DIRECT = 1 << 2,         // 0xC alias uncached
  MEM_FLAG_COHERENT = 2 << 2,       // 0x8 alias. Non-allocating in L2 but coherent
  MEM_FLAG_ZERO = 1 << 4,           // initialise buffer to all zeros
  MEM_FLAG_NO_INIT = 1 << 5,        // don't initialise (default is initialise to all ones)
  MEM_FLAG_HINT_PERMALOCK = 1 << 6, // Likely to be locked for long periods of time
  MEM_FLAG_L1_NONALLOCATING = (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT) // Allocating in L2
} VC_ALLOC_FLAGS;

// VC flags for unchached DMA memory
#define DMA_MEM_FLAGS (MEM_FLAG_DIRECT | MEM_FLAG_ZERO)

void videocore_setup(MEM_MAP *mp, int size);
void videocore_close(MEM_MAP *mp);

uint32_t alloc_vc_mem(int fd, uint32_t size, VC_ALLOC_FLAGS flags);
void *lock_vc_mem(int fd, int h);
uint32_t unlock_vc_mem(int fd, int h);
uint32_t free_vc_mem(int fd, int h);
uint32_t set_vc_clock(int fd, int id, uint32_t freq);

#endif // __RPI_VIDEOCORE_H__