/*
 * (C) Copyright 1992, ..., 2014 the "DOSEMU-Development-Team".
 *
 * for details see file COPYING in the DOSEMU distribution
 */

#ifndef DMEMORY_H
#define DMEMORY_H

typedef struct dpmi_pm_block_stuct {
  struct   dpmi_pm_block_stuct *next;
  unsigned int handle;
  unsigned int size;
  dosaddr_t base;
  u_short  *attrs;
  unsigned int linear:1;
  unsigned int hwram:1;
  unsigned int shm:1;
  char *shmname;
  char *rshmname;
  int nmoffs;
  char *shm_dir;
  void *shm_lock;
  uint32_t lock_flags;
  int mapped;
  int shm_fd;
  void *stalled_shm_addr;
#define PMBF_DJ64 1
  uint32_t flags;
  int opaque;
} dpmi_pm_block;

typedef struct dpmi_pm_block_root_struc {
  dpmi_pm_block *first_pm_block;
} dpmi_pm_block_root;

dpmi_pm_block *lookup_pm_block(dpmi_pm_block_root *root, unsigned h);
dpmi_pm_block *lookup_pm_block_by_addr(dpmi_pm_block_root *root,
	dosaddr_t addr);
dpmi_pm_block *lookup_pm_block_by_shmname(dpmi_pm_block_root *root,
	const char *shmname);
int dpmi_alloc_pool(void);
void dpmi_free_pool(void);
dpmi_pm_block *DPMI_malloc(dpmi_pm_block_root *root, unsigned int size);
dpmi_pm_block *DPMI_mallocLinear(dpmi_pm_block_root *root, unsigned int base, unsigned int size, int committed);
int DPMI_free(dpmi_pm_block_root *root, unsigned int handle);
dpmi_pm_block *DPMI_realloc(dpmi_pm_block_root *root, unsigned int handle, unsigned int newsize);
dpmi_pm_block *DPMI_reallocLinear(dpmi_pm_block_root *root, unsigned handle, unsigned newsize, int committed);
dpmi_pm_block *DPMI_mallocShared(dpmi_pm_block_root *root,
        const char *name, unsigned int size, int flags);
dpmi_pm_block *DPMI_mallocSharedNewNS(dpmi_pm_block_root *root,
        const char *name, unsigned int size, int flags);
dpmi_pm_block *DPMI_mallocSharedNS(dpmi_pm_block_root *root,
        const char *dname, const char *name, unsigned int size, int flags);
int DPMI_freeShared(dpmi_pm_block_root *root, uint32_t handle);
int DPMI_freeSharedNS(dpmi_pm_block_root *root, uint32_t handle);
int DPMI_freeShPartial(dpmi_pm_block_root *root, uint32_t handle);
void DPMI_freeAll(dpmi_pm_block_root *root, dpmi_pm_block *p);
int DPMI_MapConventionalMemory(dpmi_pm_block_root *root, unsigned handle,
  unsigned offset, unsigned low_addr, unsigned cnt);
int DPMI_MapDevice(dpmi_pm_block_root *root, unsigned handle,
  unsigned offset, int cnt, unsigned paddr);
dpmi_pm_block * DPMI_mapHWRam(dpmi_pm_block_root *root,
  dosaddr_t base, unsigned int size);
int DPMI_unmapHWRam(dpmi_pm_block_root *root, dosaddr_t vbase);
int DPMI_SetPageAttributes(dpmi_pm_block_root *root, unsigned handle, int offs, u_short attrs[], int count);
int DPMI_GetPageAttributes(dpmi_pm_block_root *root, unsigned handle, int offs, u_short attrs[], int count);
int dpmi_lin_mem_rsv(void);
int dpmi_lin_mem_size(void);
int dpmi_lin_mem_free(void);
int dpmi_free_memory(void);
int dpmi_alloced_memory(void);
int dpmi_largest_memory_block(void);

#endif
