blob: 007ae860346fa32dc88b445c78c8fd4b7a6919e1 [file] [log] [blame]
Simon Glass3d750d72011-09-26 14:10:39 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02003 * SPDX-License-Identifier: GPL-2.0+
Simon Glass3d750d72011-09-26 14:10:39 +00004 */
Simon Glass70778bc2015-03-05 12:25:26 -07005#define DEBUG
Simon Glass3d750d72011-09-26 14:10:39 +00006#include <common.h>
Simon Glass19200512014-07-23 06:55:02 -06007#include <dm/root.h>
Simon Glasscd0684f2011-10-03 19:26:44 +00008#include <os.h>
Simon Glass9dd10bf2013-11-10 10:27:03 -07009#include <asm/state.h>
Simon Glass3d750d72011-09-26 14:10:39 +000010
11DECLARE_GLOBAL_DATA_PTR;
12
Simon Glass70778bc2015-03-05 12:25:26 -070013/* Enable access to PCI memory with map_sysmem() */
14static bool enable_pci_map;
15
16#ifdef CONFIG_PCI
17/* Last device that was mapped into memory, and length of mapping */
18static struct udevice *map_dev;
19unsigned long map_len;
20#endif
21
Simon Glassdc9f8cd2013-11-10 10:27:00 -070022void reset_cpu(ulong ignored)
Simon Glass3d750d72011-09-26 14:10:39 +000023{
Simon Glass9dd10bf2013-11-10 10:27:03 -070024 if (state_uninit())
25 os_exit(2);
26
Simon Glass19200512014-07-23 06:55:02 -060027 if (dm_uninit())
28 os_exit(2);
29
Simon Glasscd0684f2011-10-03 19:26:44 +000030 /* This is considered normal termination for now */
31 os_exit(0);
Simon Glassdc9f8cd2013-11-10 10:27:00 -070032}
33
34int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
35{
36 reset_cpu(0);
37
Simon Glass3d750d72011-09-26 14:10:39 +000038 return 0;
39}
40
41/* delay x useconds */
42void __udelay(unsigned long usec)
43{
Matthias Weisser0d3dd142011-11-29 12:16:40 +010044 os_usleep(usec);
Simon Glass3d750d72011-09-26 14:10:39 +000045}
46
Simon Glasse7f1eb52013-06-11 11:14:44 -070047unsigned long __attribute__((no_instrument_function)) timer_get_us(void)
Simon Glass3d750d72011-09-26 14:10:39 +000048{
Matthias Weisser0d3dd142011-11-29 12:16:40 +010049 return os_get_nsec() / 1000;
Simon Glass3d750d72011-09-26 14:10:39 +000050}
51
52int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
53{
Simon Glassdc9f8cd2013-11-10 10:27:00 -070054 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;
Simon Glass3d750d72011-09-26 14:10:39 +000062}
63
64int cleanup_before_linux(void)
65{
66 return 0;
67}
68
69void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
70{
Simon Glass70778bc2015-03-05 12:25:26 -070071#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
Simon Glass64371472012-12-13 20:49:11 +000086 return (void *)(gd->arch.ram_buf + paddr);
Simon Glass3d750d72011-09-26 14:10:39 +000087}
88
Simon Glass70778bc2015-03-05 12:25:26 -070089void 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
99void sandbox_set_enable_pci_map(int enable)
100{
101 enable_pci_map = enable;
102}
103
Simon Glassf7c3f6f2014-02-27 13:25:55 -0700104phys_addr_t map_to_sysmem(const void *ptr)
Simon Glasse23d2932013-04-20 08:42:37 +0000105{
106 return (u8 *)ptr - gd->arch.ram_buf;
107}
108
Simon Glass3d750d72011-09-26 14:10:39 +0000109void flush_dcache_range(unsigned long start, unsigned long stop)
110{
111}