memory: drop find_ram_block()

On the one hand, we have already qemu_get_ram_block() whose function
is similar. On the other hand, we can directly use mr->ram_block but
searching RAMblock by ram_addr which is a kind of waste.

Backports commit fa53a0e53efdc7002497ea4a76aacf6cceb170ef from qemu
This commit is contained in:
Gonglei 2018-02-24 02:52:14 -05:00 committed by Lioncash
parent 9bb67a3f58
commit feff56cc11
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
3 changed files with 5 additions and 22 deletions

View file

@ -1049,28 +1049,13 @@ static void qemu_ram_setup_dump(void *addr, ram_addr_t size)
{ {
} }
static RAMBlock *find_ram_block(struct uc_struct *uc, ram_addr_t addr)
{
RAMBlock *block;
QLIST_FOREACH(block, &uc->ram_list.blocks, next) {
if (block->offset == addr) {
return block;
}
}
return NULL;
}
const char *qemu_ram_get_idstr(RAMBlock *rb) const char *qemu_ram_get_idstr(RAMBlock *rb)
{ {
return rb->idstr; return rb->idstr;
} }
void qemu_ram_unset_idstr(struct uc_struct *uc, ram_addr_t addr) void qemu_ram_unset_idstr(struct uc_struct *uc, RAMBlock *block)
{ {
RAMBlock *block = find_ram_block(uc, addr);
if (block) { if (block) {
memset(block->idstr, 0, sizeof(block->idstr)); memset(block->idstr, 0, sizeof(block->idstr));
} }
@ -1088,10 +1073,8 @@ static int memory_try_enable_merging(void *addr, size_t len)
* resize callback to update device state and/or add assertions to detect * resize callback to update device state and/or add assertions to detect
* misuse, if necessary. * misuse, if necessary.
*/ */
int qemu_ram_resize(struct uc_struct *uc, ram_addr_t base, ram_addr_t newsize, Error **errp) int qemu_ram_resize(struct uc_struct *uc, RAMBlock *block, ram_addr_t newsize, Error **errp)
{ {
RAMBlock *block = find_ram_block(uc, base);
assert(block); assert(block);
newsize = TARGET_PAGE_ALIGN(newsize); newsize = TARGET_PAGE_ALIGN(newsize);

View file

@ -52,8 +52,8 @@ MemoryRegion *qemu_ram_addr_from_host(struct uc_struct* uc, void *ptr, ram_addr_
RAMBlock *qemu_ram_block_by_name(struct uc_struct* uc, const char *name); RAMBlock *qemu_ram_block_by_name(struct uc_struct* uc, const char *name);
RAMBlock *qemu_ram_block_from_host(struct uc_struct* uc, void *ptr, bool round_offset, RAMBlock *qemu_ram_block_from_host(struct uc_struct* uc, void *ptr, bool round_offset,
ram_addr_t *ram_addr, ram_addr_t *offset); ram_addr_t *ram_addr, ram_addr_t *offset);
void qemu_ram_set_idstr(struct uc_struct *uc, ram_addr_t addr, const char *name, DeviceState *dev); void qemu_ram_set_idstr(struct uc_struct *uc, RAMBlock *block, const char *name, DeviceState *dev);
void qemu_ram_unset_idstr(struct uc_struct *uc, ram_addr_t addr); void qemu_ram_unset_idstr(struct uc_struct *uc, RAMBlock *block);
const char *qemu_ram_get_idstr(RAMBlock *rb); const char *qemu_ram_get_idstr(RAMBlock *rb);
bool cpu_physical_memory_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, bool cpu_physical_memory_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,

View file

@ -65,7 +65,7 @@ int qemu_get_ram_fd(struct uc_struct *uc, ram_addr_t addr);
void *qemu_get_ram_block_host_ptr(struct uc_struct *uc, ram_addr_t addr); void *qemu_get_ram_block_host_ptr(struct uc_struct *uc, ram_addr_t addr);
void qemu_ram_free(struct uc_struct *c, ram_addr_t addr); void qemu_ram_free(struct uc_struct *c, ram_addr_t addr);
int qemu_ram_resize(struct uc_struct *c, ram_addr_t base, ram_addr_t newsize, Error **errp); int qemu_ram_resize(struct uc_struct *c, RAMBlock *block, ram_addr_t newsize, Error **errp);
#define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1) #define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1)
#define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE)) #define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))