2 * Copyright (c) 2011 The Chromium OS Authors.
3 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/state.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 /* Enable access to PCI memory with map_sysmem() */
17 static bool enable_pci_map;
20 /* Last device that was mapped into memory, and length of mapping */
21 static struct udevice *map_dev;
22 unsigned long map_len;
25 void sandbox_exit(void)
27 /* Do this here while it still has an effect */
35 /* This is considered normal termination for now */
39 /* delay x useconds */
40 void __udelay(unsigned long usec)
42 struct sandbox_state *state = state_get_current();
44 if (!state->skip_delays)
48 int cleanup_before_linux(void)
53 int cleanup_before_linux_select(int flags)
58 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
61 unsigned long plen = len;
65 if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
67 printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
68 __func__, paddr, len, plen);
75 return (void *)(gd->arch.ram_buf + paddr);
78 void unmap_physmem(const void *vaddr, unsigned long flags)
82 pci_unmap_physmem(vaddr, map_len, map_dev);
88 void sandbox_set_enable_pci_map(int enable)
90 enable_pci_map = enable;
93 phys_addr_t map_to_sysmem(const void *ptr)
95 return (u8 *)ptr - gd->arch.ram_buf;
98 void flush_dcache_range(unsigned long start, unsigned long stop)
102 int sandbox_read_fdt_from_file(void)
104 struct sandbox_state *state = state_get_current();
105 const char *fname = state->fdt_fname;
111 blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
112 if (!state->fdt_fname) {
113 err = fdt_create_empty_tree(blob, 256);
116 printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
120 err = os_get_filesize(fname, &size);
122 printf("Failed to file FDT file '%s'\n", fname);
125 fd = os_open(fname, OS_O_RDONLY);
127 printf("Failed to open FDT file '%s'\n", fname);
130 if (os_read(fd, blob, size) != size) {