cpu.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. DECLARE_GLOBAL_DATA_PTR;
  11. /* Enable access to PCI memory with map_sysmem() */
  12. static bool enable_pci_map;
  13. #ifdef CONFIG_PCI
  14. /* Last device that was mapped into memory, and length of mapping */
  15. static struct udevice *map_dev;
  16. unsigned long map_len;
  17. #endif
  18. void reset_cpu(ulong ignored)
  19. {
  20. if (state_uninit())
  21. os_exit(2);
  22. if (dm_uninit())
  23. os_exit(2);
  24. /* This is considered normal termination for now */
  25. os_exit(0);
  26. }
  27. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  28. {
  29. reset_cpu(0);
  30. return 0;
  31. }
  32. /* delay x useconds */
  33. void __udelay(unsigned long usec)
  34. {
  35. os_usleep(usec);
  36. }
  37. unsigned long __attribute__((no_instrument_function)) timer_get_us(void)
  38. {
  39. return os_get_nsec() / 1000;
  40. }
  41. int cleanup_before_linux(void)
  42. {
  43. return 0;
  44. }
  45. void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  46. {
  47. #ifdef CONFIG_PCI
  48. unsigned long plen = len;
  49. void *ptr;
  50. map_dev = NULL;
  51. if (enable_pci_map && !pci_map_physmem(paddr, &len, &map_dev, &ptr)) {
  52. if (plen != len) {
  53. printf("%s: Warning: partial map at %x, wanted %lx, got %lx\n",
  54. __func__, paddr, len, plen);
  55. }
  56. map_len = len;
  57. return ptr;
  58. }
  59. #endif
  60. return (void *)(gd->arch.ram_buf + paddr);
  61. }
  62. void unmap_physmem(const void *vaddr, unsigned long flags)
  63. {
  64. #ifdef CONFIG_PCI
  65. if (map_dev) {
  66. pci_unmap_physmem(vaddr, map_len, map_dev);
  67. map_dev = NULL;
  68. }
  69. #endif
  70. }
  71. void sandbox_set_enable_pci_map(int enable)
  72. {
  73. enable_pci_map = enable;
  74. }
  75. phys_addr_t map_to_sysmem(const void *ptr)
  76. {
  77. return (u8 *)ptr - gd->arch.ram_buf;
  78. }
  79. void flush_dcache_range(unsigned long start, unsigned long stop)
  80. {
  81. }