cpu.c 2.4 KB

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