[ARM] arm32ve: arm64: Remove dependency of arch_regs.h on generic_timer.h

The arch_regs.h is indirectly included at potentially everywhere. We should
have minimum dependency of arch_regs.h on other headers hence this patch.

Also, this patch makes it clear that if we want a structure instance in
arch_regs.h then the structure should be defined in arch_regs.h or the
structure instance should be a void pointer.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_timer: Querying timer event expiry time

This adds a function to return the timestamp at which
the given timer event will expire.

Signed-off-by: Himanshu Chauhan <hschauhan@nulltrace.org>
[CORE] vmm_limits.h: Add defines for MIN & MAX values of integer types

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] arm32ve: arm64: Minor fix arch_vcpu_deinit()

We should deinit generic timer for VCPU in arch_vcpu_deinit() only if
VCPU has generic timer feature.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_workqueue: Allow vmm_work to be rescheduled when it is in-progress

There is no reason why we should not allow vmm_work to be rescheduled when
it is in-progress. This patch make re-scheduling of vmm_work more flexible.

Also, the system workqueue should not have higher priority then general
threads and Guest VCPUs. In future, many parts of Xvisor will use system
workqueue for deferring work hence we don't want such deferred work to
prempt threads and Guest VCPUs.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_manager: Introduce per-guest request APIs

There would be many situations in device emulation where we would
require to schedule a work/request for Guest because we have to do
it only in sleepable context. Examples of such situations are:
system reboot, system poweroff/shutdown, PCIe device BAR progamming,
etc.

To simplify writing deferred work/request in above described situations
we introduce per-guest request APIs. This will enable us to schedule a
callback function in system workqueue for given Guest with just one
API call. Also, all per-guest request of a Guest will be ignored if a
Guest is destroyed before they are processed.

Signed-off-by: Anup Patel <anup@brainfault.org>
[EMULATORS] arm_sysregs: Use per-guest request APIs for reboot & shutdown

This patch simplifies arm_sysregs by using per-guest request APIs for
reboot & shutdown.

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] Move MPIDR related defines to cpu_defines.h

We would be needing MPIDR related defines in SMP operations,
boot-time setup, and PSCI emulation hence we move them to
cpu_defines.h

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] Add necessary stuff for PSCI v0.2 emulation

We will need to know the PSCI version to be emulated for the
Guest hence this patch adds psci_version variable in arch
specific Guest context and also adds optional "psci_version"
attribute for Guest device tree node.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_manager: Add for-loop macro to iterate over each Guest VCPU

This patch adds for_each_guest_vcpu() macro to iterate over each
Guest VCPU in a for-loop without guest->vcpu_lock held.

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] Add support for PSCI v0.2 emulation

Currently, we only emulated PSCI v0.1 for Guest VCPUs.

This patch extends current PSCI emulation to emulate both
PSCI v0.1 and PSCI v0.2 for Guest VCPUs.

The PSCI version to emulate will be selected via Guest
device tree node attribute "psci_version".

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] vmm_manager: Add API to track guest reset timestamp

Knowing the Guest reset timestamp can be very handy hence
this patch.

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] generic_timer: Use guest reset timestamp as virtual counter offset

For SMP guest, all VCPUs should see same value of virtual counter hence
we need to use same virtual counter offset for all VCPUs. This patch
updates generic timer to use guest reset timestamp as virtual counter
offset for all Guest VCPUs.

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] emulate_psci: Fix minor typo

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] Don't return error if PSCI emulation fails

If PSCI emulation fails then simply halt the VCPU or inject
undefined exception instead of returning error.

Signed-off-by: Anup Patel <anup@brainfault.org>
[TESTS] Use PSCI v0.2 for Virt-v7 Guest

Signed-off-by: Anup Patel <anup@brainfault.org>
[TESTS] Use PSCI v0.2 for Virt-v8 Guest

Signed-off-by: Anup Patel <anup@brainfault.org>
[ARM] generic_timer: Fix virtual counter offset calculation

We cannot directly programme guest reset timestamp in virtual counter offset
because it is in nanoseconds. We need to first convert timestamp nanoseconds
to generic_timer_hz count and then treat this as virtual counter offset.

Signed-off-by: Anup Patel <anup@brainfault.org>
[CORE] Minor fix in vmm_devtree_getchild()

We can get path parameter in vmm_devtree_getchild with leading
"/" characters hence for sanity we should ingore all leading
"/" characters from path parameter.

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