blob: f0dafedc254fb5d0ca3973946539babf7a75d267 [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
Simon Glass3d750d72011-09-26 14:10:39 +000052int cleanup_before_linux(void)
53{
54 return 0;
55}
56
57void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
58{
Simon Glass70778bc2015-03-05 12:25:26 -070059#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
Simon Glass64371472012-12-13 20:49:11 +000074 return (void *)(gd->arch.ram_buf + paddr);
Simon Glass3d750d72011-09-26 14:10:39 +000075}
76
Simon Glass70778bc2015-03-05 12:25:26 -070077void 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
87void sandbox_set_enable_pci_map(int enable)
88{
89 enable_pci_map = enable;
90}
91
Simon Glassf7c3f6f2014-02-27 13:25:55 -070092phys_addr_t map_to_sysmem(const void *ptr)
Simon Glasse23d2932013-04-20 08:42:37 +000093{
94 return (u8 *)ptr - gd->arch.ram_buf;
95}
96
Simon Glass3d750d72011-09-26 14:10:39 +000097void flush_dcache_range(unsigned long start, unsigned long stop)
98{
99}