ARM: sunxi: get script.bin file name from env

All the other files can be overridden by env settings, what's so
special about script.bin?

Use the "script" env variable instead of hard-coding script.bin
everywhere; still defaults to "script.bin", but can be overridden
from uEnv.txt or boot.scr.

Signed-off-by: Patrick Wood <patrickhwood@gmail.com>
sunxi: add board Inet 86vz

Signed-off-by: Luc Verhaegen <libv@skynet.be>
sunxi: Add zatab support

Signed-off-by: Emilio López <emilio@elopez.com.ar>
sunxi: Fix sunxi_dram_init() prototypes

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi: correct CLK_DLY configuration loop

It seems that the intention was to index the dqs_dly array with dqs_i and not
clk_i. Using clk_i means that dqs_i is unused in the loop and also causes us to
run off the end of the dqs_dly array resulting in:

In file included from dram.c:34:0:
dram.c: In function ‘dramc_init’:
dram.c:314:15: warning: iteration 7u invokes undefined behavior [-Waggressive-loop-optimizations]
       (dqs_dly[clk_i] & 0x4f) << 14);

(clk_i runs to <15, dqs_i to <7 and dqs_dly[] has 8 entries)

I have not run this on actual hardware. I'm not sure when it is even used
because it is gated on "para->tpr3 & (0x1 << 31)" and AFAICT all
board/sunxi/dram_* files currently in the tree set trp3 to zero.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
cmd_gpio: fix warning with GPIO_OSCILLATE

In do_gpio value is not initialised in the GPIO_OSCILLATE case:

cmd_gpio.c: In function ‘do_gpio’:
cmd_gpio.c:92:2: warning: ‘value’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  return value;
  ^

Returning 0 in this case seems fairly logical.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Cc: Henrik Nordstrom <henrik@henriknordstrom.net>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ARM: HYP/non-sec: fix alignment requirements for vectors

Make sure the vectors are aligned on a 32 byte boundary, not
the code that deals with it...

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: move switch to non-sec to the last boot phase

Having the switch to non-secure in the "prep" phase is causing
all kind of troubles, as that stage can be called multiple times.

Instead, move the switch to non-secure to the last possible phase,
when there is no turning back anymore.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add a barrier after setting SCR.NS==1

A CP15 instruction execution can be reordered, requiring an
isb to be sure it is executed in program order.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: non-sec: reset CNTVOFF to zero

Before switching to non-secure, make sure that CNTVOFF is set
to zero on all CPUs. Otherwise, kernel running in non-secure
without HYP enabled (hence using virtual timers) may observe
timers that are not synchronized, effectively seeing time
going backward...

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: add missing HYP mode constant

In order to be able to use the various mode constants (far more
readable than random hex values), add the missing HYP and A
values.

Also update arm/lib/interrupts.c to display HYP instead of an
unknown value.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add separate section for secure code

In anticipation of refactoring the HYP/non-secure code to run
from secure RAM, add a new linker section that will contain that
code.

Nothing is using it just yet.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: allow relocation to secure RAM

The current non-sec switching code suffers from one major issue:
it cannot run in secure RAM, as a large part of u-boot still needs
to be run while we're switched to non-secure.

This patch reworks the whole HYP/non-secure strategy by:
- making sure the secure code is the *last* thing u-boot executes
  before entering the payload
- performing an exception return from secure mode directly into
  the payload
- allowing the code to be dynamically relocated to secure RAM
  before switching to non-secure.

This involves quite a bit of horrible code, specially as u-boot
relocation is quite primitive.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add generic ARMv7 PSCI code

Implement core support for PSCI. As this is generic code, it doesn't
implement anything really useful (all the functions are returning
Not Implemented).

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec: add the option for a second-stage monitor

Allow the switch to a second stage secure monitor just before
switching to non-secure.

This allows a resident piece of firmware to be active once the
kernel has been entered (the u-boot monitor is dead anyway,
its pages being reused).

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: HYP/non-sec/PSCI: emit DT nodes

Generate the PSCI node in the device tree.

Also add a reserve section for the "secure" code that lives in
in normal RAM, so that the kernel knows it'd better not trip on
it.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
sunxi: fix SRAM_B/SRAM_D memory map

Move the B and D SRAM bank to their actual location (or at least
where the documentation pretends they are).

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
sunxi: HYP/non-sec: add sun7i PSCI backend

So far, only supporting the CPU_ON method.
Other functions can be added later.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
sunxi: HYP/non-sec: configure CNTFRQ on all CPUs

CNTFRQ needs to be properly configured on all CPUs. Otherwise,
virtual machines hoping to find valuable information on secondary
CPUs will be disapointed...

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: PSCI: fix PSCI DT nodes generation failure

Currently, PSCI nodes are added after fdt has shrunk to its actual size.
Thus there may be not enough room to do so.
This patch move the nodes insertion to image_setup_libfdt,
where fdt still has much free space.
This patch rename the hook arch_fixup_memory_node to more generic
arch_fixup_fdt, to avoid adding another ARM specific hook to
arch neutral code, then make arch_fixup_fdt fixup memory node and insert
the PSCI DT nodes.

Signed-off-by: Ma Haijun <mahaijuns@gmail.com>