diff options
author | Tom Rini <trini@konsulko.com> | 2024-09-18 13:07:19 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-09-18 13:07:19 -0600 |
commit | c17805e19b9335e1fb5295c81b59eddf88d1b9ec (patch) | |
tree | 0e4cbc44f392b9f2e53d1e38e107ec630c0267c9 /arch/sandbox/cpu/cpu.c | |
parent | 650883a568653f37ee4ff43beda56152b594a49c (diff) | |
parent | 017b441b2e3c879b20bcac496369f1213c4bdbcd (diff) |
Merge patch series "Fix various bugs"
Simon Glass <sjg@chromium.org> says:
This series includes the patches needed to make make the EFI 'boot' test
work. That test has now been split off into a separate series along with
the EFI patches.
This series fixes these problems:
- sandbox memory-mapping conflict with PCI
- the fix for that causes the mbr test to crash as it sets up pointers
instead of addresses for its 'mmc' commands
- the mmc and read commands which cast addresses to pointers
- a tricky bug to do with USB keyboard and stdio
- a few other minor things
Diffstat (limited to 'arch/sandbox/cpu/cpu.c')
-rw-r--r-- | arch/sandbox/cpu/cpu.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 4f15a560902..51ce40e7f08 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -109,8 +109,9 @@ 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) { - debug("%s: Used map from %lx to %p\n", __func__, - (ulong)paddr, mentry->ptr); + log_debug("Used map from %lx to %p\n", (ulong)paddr, + mentry->ptr); + mentry->refcnt++; return mentry->ptr; } } @@ -130,11 +131,12 @@ struct sandbox_mapmem_entry *find_tag(const void *ptr) list_for_each_entry(mentry, &state->mapmem_head, sibling_node) { if (mentry->ptr == ptr) { - debug("%s: Used map from %p to %lx\n", __func__, ptr, - mentry->tag); + log_debug("Used map from %p to %lx\n", ptr, + mentry->tag); return mentry; } } + return NULL; } @@ -156,7 +158,7 @@ phys_addr_t virt_to_phys(void *ptr) __func__, ptr, (ulong)gd->ram_size); os_abort(); } - debug("%s: Used map from %p to %lx\n", __func__, ptr, mentry->tag); + log_debug("Used map from %p to %lx\n", ptr, mentry->tag); return mentry->tag; } @@ -174,6 +176,7 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) __func__, (uint)paddr, len, plen); } map_len = len; + log_debug("pci map %lx -> %p\n", (ulong)paddr, ptr); return ptr; } #endif @@ -183,12 +186,30 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) void unmap_physmem(const void *ptr, unsigned long flags) { + struct sandbox_mapmem_entry *mentry; + #ifdef CONFIG_PCI if (map_dev) { pci_unmap_physmem(ptr, map_len, map_dev); map_dev = NULL; } #endif + + /* If it is in emulated RAM, we didn't create a tag, so nothing to do */ + if (is_in_sandbox_mem(ptr)) + return; + + mentry = find_tag(ptr); + if (mentry) { + if (!--mentry->refcnt) { + list_del(&mentry->sibling_node); + log_debug("Removed map from %p to %lx\n", ptr, + (ulong)mentry->tag); + free(mentry); + } + } else { + log_warning("Address not mapped: %p\n", ptr); + } } phys_addr_t map_to_sysmem(const void *ptr) @@ -217,11 +238,14 @@ phys_addr_t map_to_sysmem(const void *ptr) } mentry->tag = state->next_tag++; mentry->ptr = (void *)ptr; + mentry->refcnt = 0; list_add_tail(&mentry->sibling_node, &state->mapmem_head); - debug("%s: Added map from %p to %lx\n", __func__, ptr, - (ulong)mentry->tag); + log_debug("Added map from %p to %lx\n", ptr, + (ulong)mentry->tag); } + mentry->refcnt++; + /* * Return the tag as the address to use. A later call to map_sysmem() * will return ptr |