2 * Copyright (c) 2011 The Chromium OS Authors.
3 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/state.h>
12 DECLARE_GLOBAL_DATA_PTR;
14 /* Enable access to PCI memory with map_sysmem() */
15 static bool enable_pci_map;
18 /* Last device that was mapped into memory, and length of mapping */
19 static struct udevice *map_dev;
20 unsigned long map_len;
23 void sandbox_exit(void)
25 /* Do this here while it still has an effect */
33 /* This is considered normal termination for now */
37 /* delay x useconds */
38 void __udelay(unsigned long usec)
40 struct sandbox_state *state = state_get_current();
42 if (!state->skip_delays)
46 int cleanup_before_linux(void)
51 int cleanup_before_linux_select(int flags)
56 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
59 unsigned long plen = len;
63 if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
65 printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
66 __func__, paddr, len, plen);
73 return (void *)(gd->arch.ram_buf + paddr);
76 void unmap_physmem(const void *vaddr, unsigned long flags)
80 pci_unmap_physmem(vaddr, map_len, map_dev);
86 void sandbox_set_enable_pci_map(int enable)
88 enable_pci_map = enable;
91 phys_addr_t map_to_sysmem(const void *ptr)
93 return (u8 *)ptr - gd->arch.ram_buf;
96 void flush_dcache_range(unsigned long start, unsigned long stop)
100 int sandbox_read_fdt_from_file(void)
102 struct sandbox_state *state = state_get_current();
103 const char *fname = state->fdt_fname;
109 blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
110 if (!state->fdt_fname) {
111 err = fdt_create_empty_tree(blob, 256);
114 printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
118 err = os_get_filesize(fname, &size);
120 printf("Failed to file FDT file '%s'\n", fname);
123 fd = os_open(fname, OS_O_RDONLY);
125 printf("Failed to open FDT file '%s'\n", fname);
128 if (os_read(fd, blob, size) != size) {