-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
psci reset with wdog #1849
Merged
+282
−9
Merged
psci reset with wdog #1849
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0625a54
core: mmu: typo fix
MrVan 416b5e8
core: dt: typo fix
MrVan e7296f8
core: dt: introduce dt_have_prop
MrVan c8bb8f0
core: dt: fix getting address and size
MrVan 12a2a40
core: arm: introduce get_dt_blob
MrVan 25bc79f
core: mmu: introduce CFG_MMAP_REGIONS
MrVan e81fe41
core: drivers: add imx wdog support
MrVan f65725a
core: arm: imx set CFG_MMAP_REGIONS
MrVan d4f4bc2
core: imx: implement psci reset
MrVan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* Copyright 2017 NXP | ||
* | ||
* Peng Fan <peng.fan@nxp.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <drivers/imx_wdog.h> | ||
#include <io.h> | ||
#include <keep.h> | ||
#include <kernel/dt.h> | ||
#include <kernel/generic_boot.h> | ||
#include <kernel/panic.h> | ||
#include <libfdt.h> | ||
#include <mm/core_mmu.h> | ||
#include <mm/core_memprot.h> | ||
#include <util.h> | ||
|
||
static bool ext_reset; | ||
static vaddr_t wdog_base; | ||
|
||
void imx_wdog_restart(void) | ||
{ | ||
uint32_t val; | ||
|
||
if (!wdog_base) { | ||
EMSG("No wdog mapped\n"); | ||
panic(); | ||
} | ||
|
||
if (ext_reset) | ||
val = 0x14; | ||
else | ||
val = 0x24; | ||
|
||
DMSG("val %x\n", val); | ||
|
||
write16(val, wdog_base + WCR_OFF); | ||
dsb(); | ||
|
||
if (read32(wdog_base + WDT_WCR) & WDT_WCR_WDE) { | ||
write32(WDT_SEQ1, wdog_base + WDT_WSR); | ||
write32(WDT_SEQ2, wdog_base + WDT_WSR); | ||
} | ||
|
||
write16(val, wdog_base + WCR_OFF); | ||
write16(val, wdog_base + WCR_OFF); | ||
|
||
while (1) | ||
; | ||
} | ||
KEEP_PAGER(imx_wdog_restart); | ||
|
||
static TEE_Result imx_wdog_init(void) | ||
{ | ||
enum teecore_memtypes mtype; | ||
void *fdt; | ||
paddr_t pbase; | ||
vaddr_t vbase; | ||
ssize_t sz; | ||
int off; | ||
int st; | ||
uint32_t i; | ||
|
||
#ifdef CFG_MX7 | ||
static const char * const wdog_path[] = { | ||
"/soc/aips-bus@30000000/wdog@30280000", | ||
"/soc/aips-bus@30000000/wdog@30290000", | ||
"/soc/aips-bus@30000000/wdog@302a0000", | ||
"/soc/aips-bus@30000000/wdog@302b0000", | ||
}; | ||
#else | ||
static const char * const wdog_path[] = { | ||
"/soc/aips-bus@02000000/wdog@020bc000", | ||
"/soc/aips-bus@02000000/wdog@020c0000", | ||
}; | ||
#endif | ||
|
||
fdt = get_dt_blob(); | ||
if (!fdt) { | ||
EMSG("No DTB\n"); | ||
return TEE_ERROR_NOT_SUPPORTED; | ||
} | ||
|
||
/* search the first usable wdog */ | ||
for (i = 0; i < ARRAY_SIZE(wdog_path); i++) { | ||
off = fdt_path_offset(fdt, wdog_path[i]); | ||
if (off < 0) | ||
continue; | ||
|
||
st = _fdt_get_status(fdt, off); | ||
if (st & DT_STATUS_OK_SEC) | ||
break; | ||
} | ||
|
||
if (i == ARRAY_SIZE(wdog_path)) | ||
return TEE_ERROR_ITEM_NOT_FOUND; | ||
|
||
DMSG("path: %s\n", wdog_path[i]); | ||
|
||
ext_reset = dt_have_prop(fdt, off, "fsl,ext-reset-output"); | ||
|
||
pbase = _fdt_reg_base_address(fdt, off); | ||
if (pbase == (paddr_t)-1) | ||
return TEE_ERROR_ITEM_NOT_FOUND; | ||
|
||
sz = _fdt_reg_size(fdt, off); | ||
if (sz < 0) | ||
return TEE_ERROR_ITEM_NOT_FOUND; | ||
|
||
if ((st & DT_STATUS_OK_SEC) && !(st & DT_STATUS_OK_NSEC)) | ||
mtype = MEM_AREA_IO_SEC; | ||
else | ||
mtype = MEM_AREA_IO_NSEC; | ||
|
||
/* | ||
* Check to see whether it has been mapped using | ||
* register_phys_mem or not. | ||
*/ | ||
vbase = (vaddr_t)phys_to_virt(pbase, mtype); | ||
if (!vbase) { | ||
if (!core_mmu_add_mapping(mtype, pbase, sz)) { | ||
EMSG("Failed to map %zu bytes at PA 0x%"PRIxPA, | ||
(size_t)sz, pbase); | ||
return TEE_ERROR_GENERIC; | ||
} | ||
} | ||
|
||
vbase = (vaddr_t)phys_to_virt(pbase, mtype); | ||
if (!vbase) { | ||
EMSG("Failed to get VA for PA 0x%"PRIxPA, pbase); | ||
return TEE_ERROR_GENERIC; | ||
} | ||
|
||
wdog_base = vbase; | ||
|
||
return TEE_SUCCESS; | ||
} | ||
driver_init(imx_wdog_init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2017 NXP | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef __IMX_WDOG_H | ||
#define __IMX_WDOG_H | ||
|
||
/* i.MX6/7D */ | ||
#define WDT_WCR 0x00 | ||
#define WDT_WCR_WDA BIT(5) | ||
#define WDT_WCR_SRS BIT(4) | ||
#define WDT_WCR_WRE BIT(3) | ||
#define WDT_WCR_WDE BIT(2) | ||
#define WDT_WCR_WDZST BIT(0) | ||
|
||
#define WDT_WSR 0x02 | ||
#define WDT_SEQ1 0x5555 | ||
#define WDT_SEQ2 0xAAAA | ||
|
||
/* Exposed for psci reset */ | ||
void imx_wdog_restart(void); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pointer isn't valid forever. It should be cleared when OP-TEE has initialized and exits the first time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to parse the dtb to get fsl,ext-reset-output in wdog node. In this patchset, I use driver_init(xxx_wdog_xx) to handle that. If not expose dtb here, I am not able to parse dtb for the drivers. Could we expose fdt in init_fdt, and destroy the pointer when first back to normal world? Or we create a copy of the dtb in optee secure side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you clear it before
init_primary_helper()
(after callinginit_teecore()
) returns it should be OK.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll clear it as you suggested.