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