2011-09-26 14:10:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 The Chromium OS Authors.
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-09-26 14:10:39 +00:00
|
|
|
*/
|
2015-03-05 19:25:26 +00:00
|
|
|
#define DEBUG
|
2011-09-26 14:10:39 +00:00
|
|
|
#include <common.h>
|
2014-07-23 12:55:02 +00:00
|
|
|
#include <dm/root.h>
|
2011-10-03 19:26:44 +00:00
|
|
|
#include <os.h>
|
2015-02-28 05:06:34 +00:00
|
|
|
#include <asm/io.h>
|
2013-11-10 17:27:03 +00:00
|
|
|
#include <asm/state.h>
|
2011-09-26 14:10:39 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2015-03-05 19:25:26 +00:00
|
|
|
/* Enable access to PCI memory with map_sysmem() */
|
|
|
|
static bool enable_pci_map;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
/* Last device that was mapped into memory, and length of mapping */
|
|
|
|
static struct udevice *map_dev;
|
|
|
|
unsigned long map_len;
|
|
|
|
#endif
|
|
|
|
|
2013-11-10 17:27:00 +00:00
|
|
|
void reset_cpu(ulong ignored)
|
2011-09-26 14:10:39 +00:00
|
|
|
{
|
2015-05-11 03:07:27 +00:00
|
|
|
/* Do this here while it still has an effect */
|
|
|
|
os_fd_restore();
|
2013-11-10 17:27:03 +00:00
|
|
|
if (state_uninit())
|
|
|
|
os_exit(2);
|
|
|
|
|
2014-07-23 12:55:02 +00:00
|
|
|
if (dm_uninit())
|
|
|
|
os_exit(2);
|
|
|
|
|
2011-10-03 19:26:44 +00:00
|
|
|
/* This is considered normal termination for now */
|
|
|
|
os_exit(0);
|
2013-11-10 17:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
reset_cpu(0);
|
|
|
|
|
2011-09-26 14:10:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delay x useconds */
|
|
|
|
void __udelay(unsigned long usec)
|
|
|
|
{
|
2011-11-29 11:16:40 +00:00
|
|
|
os_usleep(usec);
|
2011-09-26 14:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int cleanup_before_linux(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
|
|
|
|
{
|
2015-03-05 19:25:26 +00:00
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
unsigned long plen = len;
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
map_dev = NULL;
|
|
|
|
if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
|
|
|
|
if (plen != len) {
|
|
|
|
printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
|
|
|
|
__func__, paddr, len, plen);
|
|
|
|
}
|
|
|
|
map_len = len;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-13 20:49:11 +00:00
|
|
|
return (void *)(gd->arch.ram_buf + paddr);
|
2011-09-26 14:10:39 +00:00
|
|
|
}
|
|
|
|
|
2015-03-05 19:25:26 +00:00
|
|
|
void unmap_physmem(const void *vaddr, unsigned long flags)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
if (map_dev) {
|
|
|
|
pci_unmap_physmem(vaddr, map_len, map_dev);
|
|
|
|
map_dev = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sandbox_set_enable_pci_map(int enable)
|
|
|
|
{
|
|
|
|
enable_pci_map = enable;
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:25:55 +00:00
|
|
|
phys_addr_t map_to_sysmem(const void *ptr)
|
2013-04-20 08:42:37 +00:00
|
|
|
{
|
|
|
|
return (u8 *)ptr - gd->arch.ram_buf;
|
|
|
|
}
|
|
|
|
|
2011-09-26 14:10:39 +00:00
|
|
|
void flush_dcache_range(unsigned long start, unsigned long stop)
|
|
|
|
{
|
|
|
|
}
|
2015-02-28 05:06:34 +00:00
|
|
|
|
|
|
|
int sandbox_read_fdt_from_file(void)
|
|
|
|
{
|
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
const char *fname = state->fdt_fname;
|
|
|
|
void *blob;
|
|
|
|
loff_t size;
|
|
|
|
int err;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
|
|
|
|
if (!state->fdt_fname) {
|
|
|
|
err = fdt_create_empty_tree(blob, 256);
|
|
|
|
if (!err)
|
|
|
|
goto done;
|
|
|
|
printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os_get_filesize(fname, &size);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("Failed to file FDT file '%s'\n", fname);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
fd = os_open(fname, OS_O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
printf("Failed to open FDT file '%s'\n", fname);
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
if (os_read(fd, blob, size) != size) {
|
|
|
|
os_close(fd);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
os_close(fd);
|
|
|
|
|
|
|
|
done:
|
|
|
|
gd->fdt_blob = blob;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|