common: Move ARM cache operations out of common.h
[platform/kernel/u-boot.git] / arch / sandbox / cpu / cpu.c
index 6098945..ff74303 100644 (file)
@@ -2,8 +2,9 @@
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
  */
-#define DEBUG
+
 #include <common.h>
+#include <cpu_func.h>
 #include <dm.h>
 #include <errno.h>
 #include <linux/libfdt.h>
@@ -105,8 +106,8 @@ void *phys_to_virt(phys_addr_t paddr)
        state = state_get_current();
        list_for_each_entry(mentry, &state->mapmem_head, sibling_node) {
                if (mentry->tag == paddr) {
-                       printf("%s: Used map from %lx to %p\n", __func__,
-                              (ulong)paddr, mentry->ptr);
+                       debug("%s: Used map from %lx to %p\n", __func__,
+                             (ulong)paddr, mentry->ptr);
                        return mentry->ptr;
                }
        }
@@ -152,7 +153,7 @@ phys_addr_t virt_to_phys(void *ptr)
                       __func__, ptr, (ulong)gd->ram_size);
                os_abort();
        }
-       printf("%s: Used map from %p to %lx\n", __func__, ptr, mentry->tag);
+       debug("%s: Used map from %p to %lx\n", __func__, ptr, mentry->tag);
 
        return mentry->tag;
 }
@@ -225,6 +226,57 @@ phys_addr_t map_to_sysmem(const void *ptr)
        return mentry->tag;
 }
 
+unsigned int sandbox_read(const void *addr, enum sandboxio_size_t size)
+{
+       struct sandbox_state *state = state_get_current();
+
+       if (!state->allow_memio)
+               return 0;
+
+       switch (size) {
+       case SB_SIZE_8:
+               return *(u8 *)addr;
+       case SB_SIZE_16:
+               return *(u16 *)addr;
+       case SB_SIZE_32:
+               return *(u32 *)addr;
+       case SB_SIZE_64:
+               return *(u64 *)addr;
+       }
+
+       return 0;
+}
+
+void sandbox_write(void *addr, unsigned int val, enum sandboxio_size_t size)
+{
+       struct sandbox_state *state = state_get_current();
+
+       if (!state->allow_memio)
+               return;
+
+       switch (size) {
+       case SB_SIZE_8:
+               *(u8 *)addr = val;
+               break;
+       case SB_SIZE_16:
+               *(u16 *)addr = val;
+               break;
+       case SB_SIZE_32:
+               *(u32 *)addr = val;
+               break;
+       case SB_SIZE_64:
+               *(u64 *)addr = val;
+               break;
+       }
+}
+
+void sandbox_set_enable_memio(bool enable)
+{
+       struct sandbox_state *state = state_get_current();
+
+       state->allow_memio = enable;
+}
+
 void sandbox_set_enable_pci_map(int enable)
 {
        enable_pci_map = enable;