]>
Commit | Line | Data |
---|---|---|
4b0730d2 SG |
1 | /* |
2 | * Copyright (c) 2011 The Chromium OS Authors. | |
1a459660 | 3 | * SPDX-License-Identifier: GPL-2.0+ |
4b0730d2 | 4 | */ |
9569c406 | 5 | #define DEBUG |
4b0730d2 | 6 | #include <common.h> |
61336833 | 7 | #include <dm/root.h> |
7a9219c1 | 8 | #include <os.h> |
b45122fd | 9 | #include <asm/io.h> |
5c2859cd | 10 | #include <asm/state.h> |
4b0730d2 SG |
11 | |
12 | DECLARE_GLOBAL_DATA_PTR; | |
13 | ||
9569c406 SG |
14 | /* Enable access to PCI memory with map_sysmem() */ |
15 | static bool enable_pci_map; | |
16 | ||
17 | #ifdef CONFIG_PCI | |
18 | /* Last device that was mapped into memory, and length of mapping */ | |
19 | static struct udevice *map_dev; | |
20 | unsigned long map_len; | |
21 | #endif | |
22 | ||
88bd0e9d | 23 | void reset_cpu(ulong ignored) |
4b0730d2 | 24 | { |
8939df09 SG |
25 | /* Do this here while it still has an effect */ |
26 | os_fd_restore(); | |
5c2859cd SG |
27 | if (state_uninit()) |
28 | os_exit(2); | |
29 | ||
61336833 SG |
30 | if (dm_uninit()) |
31 | os_exit(2); | |
32 | ||
7a9219c1 SG |
33 | /* This is considered normal termination for now */ |
34 | os_exit(0); | |
88bd0e9d SG |
35 | } |
36 | ||
37 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
38 | { | |
39 | reset_cpu(0); | |
40 | ||
4b0730d2 SG |
41 | return 0; |
42 | } | |
43 | ||
44 | /* delay x useconds */ | |
45 | void __udelay(unsigned long usec) | |
46 | { | |
d99a6874 | 47 | os_usleep(usec); |
4b0730d2 SG |
48 | } |
49 | ||
4b0730d2 SG |
50 | int cleanup_before_linux(void) |
51 | { | |
52 | return 0; | |
53 | } | |
54 | ||
55 | void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) | |
56 | { | |
9569c406 SG |
57 | #ifdef CONFIG_PCI |
58 | unsigned long plen = len; | |
59 | void *ptr; | |
60 | ||
61 | map_dev = NULL; | |
62 | if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) { | |
63 | if (plen != len) { | |
64 | printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n", | |
65 | __func__, paddr, len, plen); | |
66 | } | |
67 | map_len = len; | |
68 | return ptr; | |
69 | } | |
70 | #endif | |
71 | ||
8ee666a7 | 72 | return (void *)(gd->arch.ram_buf + paddr); |
4b0730d2 SG |
73 | } |
74 | ||
9569c406 SG |
75 | void unmap_physmem(const void *vaddr, unsigned long flags) |
76 | { | |
77 | #ifdef CONFIG_PCI | |
78 | if (map_dev) { | |
79 | pci_unmap_physmem(vaddr, map_len, map_dev); | |
80 | map_dev = NULL; | |
81 | } | |
82 | #endif | |
83 | } | |
84 | ||
85 | void sandbox_set_enable_pci_map(int enable) | |
86 | { | |
87 | enable_pci_map = enable; | |
88 | } | |
89 | ||
66bd1cff | 90 | phys_addr_t map_to_sysmem(const void *ptr) |
781adb57 SG |
91 | { |
92 | return (u8 *)ptr - gd->arch.ram_buf; | |
93 | } | |
94 | ||
4b0730d2 SG |
95 | void flush_dcache_range(unsigned long start, unsigned long stop) |
96 | { | |
97 | } | |
b45122fd SG |
98 | |
99 | int sandbox_read_fdt_from_file(void) | |
100 | { | |
101 | struct sandbox_state *state = state_get_current(); | |
102 | const char *fname = state->fdt_fname; | |
103 | void *blob; | |
104 | loff_t size; | |
105 | int err; | |
106 | int fd; | |
107 | ||
108 | blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0); | |
109 | if (!state->fdt_fname) { | |
110 | err = fdt_create_empty_tree(blob, 256); | |
111 | if (!err) | |
112 | goto done; | |
113 | printf("Unable to create empty FDT: %s\n", fdt_strerror(err)); | |
114 | return -EINVAL; | |
115 | } | |
116 | ||
117 | err = os_get_filesize(fname, &size); | |
118 | if (err < 0) { | |
119 | printf("Failed to file FDT file '%s'\n", fname); | |
120 | return err; | |
121 | } | |
122 | fd = os_open(fname, OS_O_RDONLY); | |
123 | if (fd < 0) { | |
124 | printf("Failed to open FDT file '%s'\n", fname); | |
125 | return -EACCES; | |
126 | } | |
127 | if (os_read(fd, blob, size) != size) { | |
128 | os_close(fd); | |
129 | return -EIO; | |
130 | } | |
131 | os_close(fd); | |
132 | ||
133 | done: | |
134 | gd->fdt_blob = blob; | |
135 | ||
136 | return 0; | |
137 | } |