]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/sandbox/cpu/cpu.c
f0dafedc254fb5d0ca3973946539babf7a75d267
[karo-tx-uboot.git] / arch / sandbox / cpu / cpu.c
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  * SPDX-License-Identifier:     GPL-2.0+
4  */
5 #define DEBUG
6 #include <common.h>
7 #include <dm/root.h>
8 #include <os.h>
9 #include <asm/state.h>
10
11 DECLARE_GLOBAL_DATA_PTR;
12
13 /* Enable access to PCI memory with map_sysmem() */
14 static bool enable_pci_map;
15
16 #ifdef CONFIG_PCI
17 /* Last device that was mapped into memory, and length of mapping */
18 static struct udevice *map_dev;
19 unsigned long map_len;
20 #endif
21
22 void reset_cpu(ulong ignored)
23 {
24         if (state_uninit())
25                 os_exit(2);
26
27         if (dm_uninit())
28                 os_exit(2);
29
30         /* This is considered normal termination for now */
31         os_exit(0);
32 }
33
34 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
35 {
36         reset_cpu(0);
37
38         return 0;
39 }
40
41 /* delay x useconds */
42 void __udelay(unsigned long usec)
43 {
44         os_usleep(usec);
45 }
46
47 unsigned long __attribute__((no_instrument_function)) timer_get_us(void)
48 {
49         return os_get_nsec() / 1000;
50 }
51
52 int cleanup_before_linux(void)
53 {
54         return 0;
55 }
56
57 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
58 {
59 #ifdef CONFIG_PCI
60         unsigned long plen = len;
61         void *ptr;
62
63         map_dev = NULL;
64         if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
65                 if (plen != len) {
66                         printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
67                                __func__, paddr, len, plen);
68                 }
69                 map_len = len;
70                 return ptr;
71         }
72 #endif
73
74         return (void *)(gd->arch.ram_buf + paddr);
75 }
76
77 void unmap_physmem(const void *vaddr, unsigned long flags)
78 {
79 #ifdef CONFIG_PCI
80         if (map_dev) {
81                 pci_unmap_physmem(vaddr, map_len, map_dev);
82                 map_dev = NULL;
83         }
84 #endif
85 }
86
87 void sandbox_set_enable_pci_map(int enable)
88 {
89         enable_pci_map = enable;
90 }
91
92 phys_addr_t map_to_sysmem(const void *ptr)
93 {
94         return (u8 *)ptr - gd->arch.ram_buf;
95 }
96
97 void flush_dcache_range(unsigned long start, unsigned long stop)
98 {
99 }