[CORE] Fix a bug in vmm_waitqueue_sleep_event()

Currently, vmm_waitqueue_sleep_event does not sleep, instead yields.
With this patch, vmm_waitqueue_sleep_event sleeps infinitely instead of yeilding.

Signed-off-by: Ankit Jindal <thatsjindal@gmail.com>
[CORE] Always use buddy allocator based heap management

It has been a while since we are using buddy allocator based
heap managements. This is a very widely used memory allocator
in unix-like OSes (including Linux).

The main issue (and the only issue) with buddy allocator is
internal fragmentation because it always allocate memory in
power of 2 and some memory is always wasted in each allocation.
(Refer, http://en.wikipedia.org/wiki/Buddy_memory_allocation)

Most unix-like OSes have their own way of dealing with internal
fragmentation. Linux uses SLAB and SLUB allocator for this. We
currently have mempool APIs for this and in-future we will have
more methods of reducing internal fragmentation.

This patch makes buddy allocator mandatory for heap management.

Signed-off-by: Anup Patel <anup@brainfault.org>
Merge x86-next from https://github.com/hschauhan/xvisor-x86_64
[CORE] Introduce dma-coherent memory flag.

Moving forward, we will soon encounter DMA-capable devices.
The drivers for such DMA-capable devices may require DMA
coherent memory for using built-in DMA.

The patch introduces VMM_MEMORY_DMACOHERENT memory flag
which can be used to request dma-coherent pages.

Signed-off-by: Anup Patel <anup@brainfault.org>
[LIBS] Allow custom memory flags when creating mempool

We should be able to create mempool with different memory flags
based on requirement of mempool user. For instance one may want
to create a mempool of objects from a dma-coherent memory.

This patch updates mempool_create() API enabling us to pass
memory flags for the pool of objects.

Signed-off-by: Anup Patel <anup@brainfault.org>
[LIBS] More APIs for buddy alloctor.

This patch does following changes to buddy allocator:
1. Simplifies buddy_mem_reserve() API
2. Adds buddy_mem_find() API
3. Adds buddy_mem_pratial_free() API

Signed-off-by: Anup Patel <anup@brainfault.org>
[LIBS] Minor improvement to reduce memory wasteage in buddy allocator

We all know that we waste lot of memory in buddy allocator because
buddy allocator always gives us memory in power of 2 which leads
to some wasteage in each memory allocation.

This patch attempts to reduce this wasteage by downgrading alloced
buddy area to smallest bin and freeing some extra blocks of smallest
size from alloced area.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Don't include vmm_chardev.h in vmm_heap.h

The vmm_heap.h is included at large number of places. Any header
included in vmm_heap.h will be indirectly included at number of
places.

To force explicit include of vmm_chardev.h we remove it from
vmm_heap.h

Also, we do minor consmetic changes in vmm_heap_print_state().

Signed-off-by: Anup Patel <anup@brainfault.org>
[EMULATORS] Fix compile error in PCI emulation framework

The PCI emulation framework header does not include appropriate
header which are required by structures and function prototypes
defined in this header.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Use buddy allocator to manage VAPOOL

Currently, we use bitmap to manage VAPOOl hence we have following
runtime complexities:
VAPOOL alloc: O(n)
VAPOOL reserve: O(1)
VAPOOL free: O(1)

From above it is clear the VAPOOL allocations are slower because
of bitmap usage.

This patch introduces use of buddy allocator to manage VAPOOL
and updated runtime complexities are:
VAPOOL alloc: O(log n)
VAPOOL reserve: O(log n)
VAPOOL free: O(log n)

The patch also does few simplifications to vmm_host_aspace_init().

Signed-off-by: Anup Patel <anup@brainfault.org>
[COMMANDS] Add "host vapool state" command

We use buddy allocator to manage VAPOOL hence this patch introduce
"host vapool state" command to dump state of VAPOOL buddy allocator.

We also do few other cosmetic changes to host command such as:
1. Rename "host vapool stats" to "host vapool info"
2. Rename "host ram stats" to "host ram info"

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Add dma_mask to vmm_device

This patch adds the dma_mask to device structure which will help
driver porting, as most of the devices have inbuild dma.

Signed-off-by: Ankit Jindal <thatsjindal@gmail.com>
[DRIVERS] Add linux/dma_mapping.h for driver porting

Signed-off-by: Ankit Jindal <thatsjindal@gmail.com>
[CORE] Very crucial bug fix in vmm_host_memory_read()

We should be only reading one page at a time in vmm_host_memory_read().

Currently, if arch provides arch_cpu_aspace_memory_read() then function
vmm_host_memory_read() passes complete "len" of data to be read to
arch_cpu_aspace_memory_read() which is totally wrong instead we should
only read "page_read" bytes in each call to arch_cpu_aspace_memory_read().

This patch fixes above described issue in vmm_host_memory_read().

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_devemu: Add more debug prints for read/write emulation

We should more verbose about failure cases in memory read/write and io
read/write emulation hence this patch adds few debug prints for failure
in vmm_devemu_emulate_read/write() and vmm_devemu_emulate_ioread/iowrite().

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_devdrv: Remove few redundant APIs

This patch does minor simplification to vmm_devdrv API by removing
few API such as vmm_devdrv_class_register/unregister_device() and
and vmm_devdrv_bus_register/unregister_device() from vmm_devdrv.h

This means that now we use vmm_devdrv_register/unregister_device()
APIs to support bus/class level device registration.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Add vmm_host_vapool_find() API

This patch adds vmm_host_vapool_find() API.

This new API can be used to findout alloced/reserved
virtual space under which given virtual address falls.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Distinguish behaviour of vmm_host_memunmap() and vmm_host_free_pages()

The vmm_host_memunmap() as-per semantics should free entire alloced/reserved
virtual space whereas vmm_host_free_pages() should only free selected portion
of virtual space.

This patch does minor cosmetic changes to both this APIs so that this meaning
or semantics can be easily inferred from code.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Simplify vmm_host_memunmap() and vmm_host_iounmap() APIs

Generally in unix-like OSes (such as Linux, Free BSD, Net BSD, etc.)
the memory/io unmap functions don't require size parameter. It is
also a bit odd/non-standard to expect size parameter in these functions.

This patch removes the need of size parameter in vmm_host_memunmap()
and vmm_host_iounmap() APIs.

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] arm32: Setup 4KB pages at boot-time instead of 1MB pages

Currently, we create section entries (1MB pages) at boot-time. This
puts constraint that exection start/end (i.e. code start/end) address
have to be 1MB aligned causing waste of memory. Further, arch reserved
area (i.e. L1/L2 ttbl pools) is also 1MB aligned to simplify the
arch_cpu_aspace_primary_init() function but this also leads to waste
of memory in arch reserved area.

This patch updates boot-time code to create 4KB pages instead of 1MB
pages and also removes 1MB alignment restriction in execution start/end
and arch reserved area.

Signed-off-by: Anup Patel <anup@brainfault.org>