1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2011 The Chromium OS Authors.
9 #include <linux/libfdt.h>
12 #include <asm/setjmp.h>
13 #include <asm/state.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 /* Enable access to PCI memory with map_sysmem() */
19 static bool enable_pci_map;
22 /* Last device that was mapped into memory, and length of mapping */
23 static struct udevice *map_dev;
24 unsigned long map_len;
27 void sandbox_exit(void)
29 /* Do this here while it still has an effect */
37 /* This is considered normal termination for now */
41 /* delay x useconds */
42 void __udelay(unsigned long usec)
44 struct sandbox_state *state = state_get_current();
46 if (!state->skip_delays)
50 int cleanup_before_linux(void)
55 int cleanup_before_linux_select(int flags)
60 void *phys_to_virt(phys_addr_t paddr)
62 return (void *)(gd->arch.ram_buf + paddr);
65 phys_addr_t virt_to_phys(void *vaddr)
67 return (phys_addr_t)((uint8_t *)vaddr - gd->arch.ram_buf);
70 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
72 #if defined(CONFIG_PCI) && !defined(CONFIG_SPL_BUILD)
73 unsigned long plen = len;
77 if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
79 printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
80 __func__, (uint)paddr, len, plen);
87 return phys_to_virt(paddr);
90 void unmap_physmem(const void *vaddr, unsigned long flags)
94 pci_unmap_physmem(vaddr, map_len, map_dev);
100 void sandbox_set_enable_pci_map(int enable)
102 enable_pci_map = enable;
105 phys_addr_t map_to_sysmem(const void *ptr)
107 return (u8 *)ptr - gd->arch.ram_buf;
110 void flush_dcache_range(unsigned long start, unsigned long stop)
114 void invalidate_dcache_range(unsigned long start, unsigned long stop)
118 int sandbox_read_fdt_from_file(void)
120 struct sandbox_state *state = state_get_current();
121 const char *fname = state->fdt_fname;
127 blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
128 if (!state->fdt_fname) {
129 err = fdt_create_empty_tree(blob, 256);
132 printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
136 err = os_get_filesize(fname, &size);
138 printf("Failed to file FDT file '%s'\n", fname);
141 fd = os_open(fname, OS_O_RDONLY);
143 printf("Failed to open FDT file '%s'\n", fname);
146 if (os_read(fd, blob, size) != size) {
158 ulong timer_get_boot_us(void)
160 static uint64_t base_count;
161 uint64_t count = os_get_nsec();
166 return (count - base_count) / 1000;
169 int setjmp(jmp_buf jmp)
171 return os_setjmp((ulong *)jmp, sizeof(*jmp));
174 void longjmp(jmp_buf jmp, int ret)
176 os_longjmp((ulong *)jmp, ret);