[ARM] tegra: Add function to enable protected aperture
Change-Id: I699cee3bc9a131259b330655126146f5d1f92043
Signed-off-by: Colin Cross <ccross@android.com>
diff --git a/arch/arm/mach-tegra/common.c b/arch/arm/mach-tegra/common.c
index 56dcf60..b490e42 100644
--- a/arch/arm/mach-tegra/common.c
+++ b/arch/arm/mach-tegra/common.c
@@ -36,6 +36,8 @@
#include "fuse.h"
#include "pm.h"
+#define MC_SECURITY_CFG2 0x7c
+
unsigned long tegra_bootloader_fb_start;
unsigned long tegra_bootloader_fb_size;
unsigned long tegra_fb_start;
@@ -46,6 +48,7 @@
unsigned long tegra_carveout_size;
unsigned long tegra_lp0_vec_start;
unsigned long tegra_lp0_vec_size;
+unsigned long tegra_grhost_aperture;
void (*arch_reset)(char mode, const char *cmd) = tegra_assert_system_reset;
@@ -153,6 +156,23 @@
}
early_param("tegra_fbmem", tegra_bootloader_fb_arg);
+/*
+ * Tegra has a protected aperture that prevents access by most non-CPU
+ * memory masters to addresses above the aperture value. Enabling it
+ * secures the CPU's memory from the GPU, except through the GART.
+ */
+void __init tegra_protected_aperture_init(unsigned long aperture)
+{
+#ifndef CONFIG_NVMAP_ALLOW_SYSMEM
+ void __iomem *mc_base = IO_ADDRESS(TEGRA_MC_BASE);
+ pr_info("Enabling Tegra protected aperture at 0x%08lx\n", aperture);
+ writel(aperture, mc_base + MC_SECURITY_CFG2);
+#else
+ pr_err("Tegra protected aperture disabled because nvmap is using "
+ "system memory\n");
+#endif
+}
+
void __init tegra_reserve(unsigned long carveout_size, unsigned long fb_size,
unsigned long fb2_size)
{
@@ -186,6 +206,15 @@
else
tegra_fb_size = fb_size;
+ if (tegra_fb_size)
+ tegra_grhost_aperture = tegra_fb_start;
+
+ if (tegra_fb2_size && tegra_fb2_start < tegra_grhost_aperture)
+ tegra_grhost_aperture = tegra_fb2_start;
+
+ if (tegra_carveout_size && tegra_carveout_start < tegra_grhost_aperture)
+ tegra_grhost_aperture = tegra_carveout_start;
+
/*
* TODO: We should copy the bootloader's framebuffer to the framebuffer
* allocated above, and then free this one.