Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Arm Trusted Firmware
Commits
c64d1345
Commit
c64d1345
authored
Oct 04, 2017
by
davidcunado-arm
Committed by
GitHub
Oct 04, 2017
Browse files
Merge pull request #1109 from robertovargas-arm/mem_protect
Mem protect
parents
cb2cfae3
b09ba056
Changes
22
Hide whitespace changes
Inline
Side-by-side
plat/arm/common/arm_nor_psci_mem_protect.c
0 → 100644
View file @
c64d1345
/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <debug.h>
#include <mmio.h>
#include <norflash.h>
#include <plat_arm.h>
#include <platform_def.h>
#include <psci.h>
#include <utils.h>
mem_region_t
arm_ram_ranges
[]
=
{
{
ARM_NS_DRAM1_BASE
,
ARM_NS_DRAM1_SIZE
},
#ifdef AARCH64
{
ARM_DRAM2_BASE
,
ARM_DRAM2_SIZE
},
#endif
};
/*******************************************************************************
* Function that reads the content of the memory protect variable that
* enables clearing of non secure memory when system boots. This variable
* should be stored in a secure NVRAM.
******************************************************************************/
int
arm_psci_read_mem_protect
(
int
*
enabled
)
{
int
tmp
;
tmp
=
*
(
int
*
)
PLAT_ARM_MEM_PROT_ADDR
;
*
enabled
=
(
tmp
==
1
);
return
0
;
}
/*******************************************************************************
* Function that writes the content of the memory protect variable that
* enables overwritten of non secure memory when system boots.
******************************************************************************/
int
arm_nor_psci_write_mem_protect
(
int
val
)
{
int
enable
=
(
val
!=
0
);
if
(
nor_unlock
(
PLAT_ARM_MEM_PROT_ADDR
)
!=
0
)
{
ERROR
(
"unlocking memory protect variable
\n
"
);
return
-
1
;
}
if
(
enable
)
{
/*
* If we want to write a value different than 0
* then we have to erase the full block because
* otherwise we cannot ensure that the value programmed
* into the flash is going to be the same than the value
* requested by the caller
*/
if
(
nor_erase
(
PLAT_ARM_MEM_PROT_ADDR
)
!=
0
)
{
ERROR
(
"erasing block containing memory protect variable
\n
"
);
return
-
1
;
}
}
if
(
nor_word_program
(
PLAT_ARM_MEM_PROT_ADDR
,
enable
)
!=
0
)
{
ERROR
(
"programming memory protection variable
\n
"
);
return
-
1
;
}
return
0
;
}
/*******************************************************************************
* Function used for required psci operations performed when
* system boots
******************************************************************************/
void
arm_nor_psci_do_mem_protect
(
void
)
{
int
enable
;
arm_psci_read_mem_protect
(
&
enable
);
if
(
!
enable
)
return
;
INFO
(
"PSCI: Overwritting non secure memory
\n
"
);
clear_mem_regions
(
arm_ram_ranges
,
ARRAY_SIZE
(
arm_ram_ranges
));
arm_nor_psci_write_mem_protect
(
0
);
}
/*******************************************************************************
* Function that checks if a region is protected by the memory protect
* mechanism
******************************************************************************/
int
arm_psci_mem_protect_chk
(
uintptr_t
base
,
u_register_t
length
)
{
return
mem_region_in_array_chk
(
arm_ram_ranges
,
ARRAY_SIZE
(
arm_ram_ranges
),
base
,
length
);
}
plat/arm/css/common/css_pm.c
View file @
c64d1345
...
@@ -290,5 +290,14 @@ plat_psci_ops_t plat_arm_psci_pm_ops = {
...
@@ -290,5 +290,14 @@ plat_psci_ops_t plat_arm_psci_pm_ops = {
.
validate_ns_entrypoint
=
arm_validate_ns_entrypoint
,
.
validate_ns_entrypoint
=
arm_validate_ns_entrypoint
,
.
translate_power_state_by_mpidr
=
css_translate_power_state_by_mpidr
,
.
translate_power_state_by_mpidr
=
css_translate_power_state_by_mpidr
,
.
get_node_hw_state
=
css_node_hw_state
,
.
get_node_hw_state
=
css_node_hw_state
,
.
get_sys_suspend_power_state
=
css_get_sys_suspend_power_state
.
get_sys_suspend_power_state
=
css_get_sys_suspend_power_state
,
/*
* mem_protect is not supported in RESET_TO_BL31 and RESET_TO_SP_MIN,
* as that would require mapping in all of NS DRAM into BL31 or BL32.
*/
#if defined(PLAT_ARM_MEM_PROT_ADDR) && !RESET_TO_BL31 && !RESET_TO_SP_MIN
.
mem_protect_chk
=
arm_psci_mem_protect_chk
,
.
read_mem_protect
=
arm_psci_read_mem_protect
,
.
write_mem_protect
=
arm_nor_psci_write_mem_protect
,
#endif
};
};
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment