xref: /openbmc/u-boot/arch/sandbox/cpu/cpu.c (revision 58d423b8)
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 do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
53 {
54 	if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
55 		bootstage_mark(BOOTSTAGE_ID_RUN_OS);
56 		printf("## Transferring control to Linux (at address %08lx)...\n",
57 		       images->ep);
58 		reset_cpu(0);
59 	}
60 
61 	return 0;
62 }
63 
64 int cleanup_before_linux(void)
65 {
66 	return 0;
67 }
68 
69 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
70 {
71 #ifdef CONFIG_PCI
72 	unsigned long plen = len;
73 	void *ptr;
74 
75 	map_dev = NULL;
76 	if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
77 		if (plen != len) {
78 			printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
79 			       __func__, paddr, len, plen);
80 		}
81 		map_len = len;
82 		return ptr;
83 	}
84 #endif
85 
86 	return (void *)(gd->arch.ram_buf + paddr);
87 }
88 
89 void unmap_physmem(const void *vaddr, unsigned long flags)
90 {
91 #ifdef CONFIG_PCI
92 	if (map_dev) {
93 		pci_unmap_physmem(vaddr, map_len, map_dev);
94 		map_dev = NULL;
95 	}
96 #endif
97 }
98 
99 void sandbox_set_enable_pci_map(int enable)
100 {
101 	enable_pci_map = enable;
102 }
103 
104 phys_addr_t map_to_sysmem(const void *ptr)
105 {
106 	return (u8 *)ptr - gd->arch.ram_buf;
107 }
108 
109 void flush_dcache_range(unsigned long start, unsigned long stop)
110 {
111 }
112