Skip to content

Commit

Permalink
exec: Make ldl_*_phys input an AddressSpace
Browse files Browse the repository at this point in the history
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Edgar E. Iglesias <[email protected]>
  • Loading branch information
edgarigl committed Feb 11, 2014
1 parent 33bde2e commit fdfba1a
Show file tree
Hide file tree
Showing 30 changed files with 190 additions and 149 deletions.
5 changes: 4 additions & 1 deletion cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ int cpu_exec(CPUArchState *env)
/* FIXME: this should respect TPR */
cpu_svm_check_intercept_param(env, SVM_EXIT_VINTR,
0);
intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector));
intno = ldl_phys(cpu->as,
env->vm_vmcb
+ offsetof(struct vmcb,
control.int_vector));
qemu_log_mask(CPU_LOG_TB_IN_ASM, "Servicing virtual hardware INT=0x%02x\n", intno);
do_interrupt_x86_hardirq(env, intno, 1);
cpu->interrupt_request &= ~CPU_INTERRUPT_VIRQ;
Expand Down
19 changes: 9 additions & 10 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ static uint64_t watch_mem_read(void *opaque, hwaddr addr,
switch (size) {
case 1: return ldub_phys(addr);
case 2: return lduw_phys(addr);
case 4: return ldl_phys(addr);
case 4: return ldl_phys(&address_space_memory, addr);
default: abort();
}
}
Expand Down Expand Up @@ -2348,7 +2348,7 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len,
}

/* warning: addr must be aligned */
static inline uint32_t ldl_phys_internal(hwaddr addr,
static inline uint32_t ldl_phys_internal(AddressSpace *as, hwaddr addr,
enum device_endian endian)
{
uint8_t *ptr;
Expand All @@ -2357,8 +2357,7 @@ static inline uint32_t ldl_phys_internal(hwaddr addr,
hwaddr l = 4;
hwaddr addr1;

mr = address_space_translate(&address_space_memory, addr, &addr1, &l,
false);
mr = address_space_translate(as, addr, &addr1, &l, false);
if (l < 4 || !memory_access_is_direct(mr, false)) {
/* I/O case */
io_mem_read(mr, addr1, &val, 4);
Expand Down Expand Up @@ -2391,19 +2390,19 @@ static inline uint32_t ldl_phys_internal(hwaddr addr,
return val;
}

uint32_t ldl_phys(hwaddr addr)
uint32_t ldl_phys(AddressSpace *as, hwaddr addr)
{
return ldl_phys_internal(addr, DEVICE_NATIVE_ENDIAN);
return ldl_phys_internal(as, addr, DEVICE_NATIVE_ENDIAN);
}

uint32_t ldl_le_phys(hwaddr addr)
uint32_t ldl_le_phys(AddressSpace *as, hwaddr addr)
{
return ldl_phys_internal(addr, DEVICE_LITTLE_ENDIAN);
return ldl_phys_internal(as, addr, DEVICE_LITTLE_ENDIAN);
}

uint32_t ldl_be_phys(hwaddr addr)
uint32_t ldl_be_phys(AddressSpace *as, hwaddr addr)
{
return ldl_phys_internal(addr, DEVICE_BIG_ENDIAN);
return ldl_phys_internal(as, addr, DEVICE_BIG_ENDIAN);
}

/* warning: addr must be aligned */
Expand Down
9 changes: 5 additions & 4 deletions hw/dma/pl080.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include "hw/sysbus.h"
#include "exec/address-spaces.h"

#define PL080_MAX_CHANNELS 8
#define PL080_CONF_E 0x1
Expand Down Expand Up @@ -204,10 +205,10 @@ hw_error("DMA active\n");
if (size == 0) {
/* Transfer complete. */
if (ch->lli) {
ch->src = ldl_le_phys(ch->lli);
ch->dest = ldl_le_phys(ch->lli + 4);
ch->ctrl = ldl_le_phys(ch->lli + 12);
ch->lli = ldl_le_phys(ch->lli + 8);
ch->src = ldl_le_phys(&address_space_memory, ch->lli);
ch->dest = ldl_le_phys(&address_space_memory, ch->lli + 4);
ch->ctrl = ldl_le_phys(&address_space_memory, ch->lli + 12);
ch->lli = ldl_le_phys(&address_space_memory, ch->lli + 8);
} else {
ch->conf &= ~PL080_CCONF_E;
}
Expand Down
3 changes: 2 additions & 1 deletion hw/dma/sun4m_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "hw/sparc/sun4m.h"
#include "hw/sysbus.h"
#include "exec/address-spaces.h"
#include "trace.h"

/*
Expand Down Expand Up @@ -262,7 +263,7 @@ static uint32_t iommu_page_get_flags(IOMMUState *s, hwaddr addr)
iopte = s->regs[IOMMU_BASE] << 4;
addr &= ~s->iostart;
iopte += (addr >> (IOMMU_PAGE_SHIFT - 2)) & ~3;
ret = ldl_be_phys(iopte);
ret = ldl_be_phys(&address_space_memory, iopte);
trace_sun4m_iommu_page_get_flags(pa, iopte, ret);
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/net/vmware_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ vmw_shmem_st16(hwaddr addr, uint16_t value)
static inline uint32_t
vmw_shmem_ld32(hwaddr addr)
{
uint32_t res = ldl_le_phys(addr);
uint32_t res = ldl_le_phys(&address_space_memory, addr);
VMW_SHPRN("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
return res;
}
Expand Down
13 changes: 9 additions & 4 deletions hw/ppc/spapr_hcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,15 @@ static target_ulong deregister_vpa(CPUPPCState *env, target_ulong vpa)

static target_ulong register_slb_shadow(CPUPPCState *env, target_ulong addr)
{
CPUState *cs = ENV_GET_CPU(env);
uint32_t size;

if (addr == 0) {
hcall_dprintf("Can't cope with SLB shadow at logical 0\n");
return H_HARDWARE;
}

size = ldl_be_phys(addr + 0x4);
size = ldl_be_phys(cs->as, addr + 0x4);
if (size < 0x8) {
return H_PARAMETER;
}
Expand Down Expand Up @@ -425,14 +426,15 @@ static target_ulong deregister_slb_shadow(CPUPPCState *env, target_ulong addr)

static target_ulong register_dtl(CPUPPCState *env, target_ulong addr)
{
CPUState *cs = ENV_GET_CPU(env);
uint32_t size;

if (addr == 0) {
hcall_dprintf("Can't cope with DTL at logical 0\n");
return H_HARDWARE;
}

size = ldl_be_phys(addr + 0x4);
size = ldl_be_phys(cs->as, addr + 0x4);

if (size < 48) {
return H_PARAMETER;
Expand Down Expand Up @@ -532,6 +534,7 @@ static target_ulong h_rtas(PowerPCCPU *cpu, sPAPREnvironment *spapr,
static target_ulong h_logical_load(PowerPCCPU *cpu, sPAPREnvironment *spapr,
target_ulong opcode, target_ulong *args)
{
CPUState *cs = CPU(cpu);
target_ulong size = args[0];
target_ulong addr = args[1];

Expand All @@ -543,7 +546,7 @@ static target_ulong h_logical_load(PowerPCCPU *cpu, sPAPREnvironment *spapr,
args[0] = lduw_phys(addr);
return H_SUCCESS;
case 4:
args[0] = ldl_phys(addr);
args[0] = ldl_phys(cs->as, addr);
return H_SUCCESS;
case 8:
args[0] = ldq_phys(addr);
Expand Down Expand Up @@ -579,6 +582,8 @@ static target_ulong h_logical_store(PowerPCCPU *cpu, sPAPREnvironment *spapr,
static target_ulong h_logical_memop(PowerPCCPU *cpu, sPAPREnvironment *spapr,
target_ulong opcode, target_ulong *args)
{
CPUState *cs = CPU(cpu);

target_ulong dst = args[0]; /* Destination address */
target_ulong src = args[1]; /* Source address */
target_ulong esize = args[2]; /* Element size (0=1,1=2,2=4,3=8) */
Expand Down Expand Up @@ -611,7 +616,7 @@ static target_ulong h_logical_memop(PowerPCCPU *cpu, sPAPREnvironment *spapr,
tmp = lduw_phys(src);
break;
case 2:
tmp = ldl_phys(src);
tmp = ldl_phys(cs->as, src);
break;
case 3:
tmp = ldq_phys(src);
Expand Down
3 changes: 2 additions & 1 deletion hw/s390x/css.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <hw/qdev.h>
#include "qemu/bitops.h"
#include "exec/address-spaces.h"
#include "cpu.h"
#include "ioinst.h"
#include "css.h"
Expand Down Expand Up @@ -667,7 +668,7 @@ static void css_update_chnmon(SubchDev *sch)
/* Format 1, per-subchannel area. */
uint32_t count;

count = ldl_phys(sch->curr_status.mba);
count = ldl_phys(&address_space_memory, sch->curr_status.mba);
count++;
stl_phys(sch->curr_status.mba, count);
} else {
Expand Down
2 changes: 1 addition & 1 deletion hw/s390x/s390-virtio-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void s390_virtio_device_update_status(VirtIOS390Device *dev)

/* Update guest supported feature bitmap */

features = bswap32(ldl_be_phys(dev->feat_offs));
features = bswap32(ldl_be_phys(&address_space_memory, dev->feat_offs));
virtio_set_features(vdev, features);
}

Expand Down
5 changes: 3 additions & 2 deletions hw/s390x/virtio-ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
ret = -EFAULT;
} else {
info.queue = ldq_phys(ccw.cda);
info.align = ldl_phys(ccw.cda + sizeof(info.queue));
info.align = ldl_phys(&address_space_memory,
ccw.cda + sizeof(info.queue));
info.index = lduw_phys(ccw.cda + sizeof(info.queue)
+ sizeof(info.align));
info.num = lduw_phys(ccw.cda + sizeof(info.queue)
Expand Down Expand Up @@ -320,7 +321,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
ret = -EFAULT;
} else {
features.index = ldub_phys(ccw.cda + sizeof(features.features));
features.features = ldl_le_phys(ccw.cda);
features.features = ldl_le_phys(&address_space_memory, ccw.cda);
if (features.index < ARRAY_SIZE(dev->host_features)) {
virtio_bus_set_vdev_features(&dev->bus, features.features);
vdev->guest_features = features.features;
Expand Down
4 changes: 2 additions & 2 deletions hw/scsi/megasas.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ static int megasas_init_firmware(MegasasState *s, MegasasCmd *cmd)
pa_lo = le32_to_cpu(initq->pi_addr_lo);
pa_hi = le32_to_cpu(initq->pi_addr_hi);
s->producer_pa = ((uint64_t) pa_hi << 32) | pa_lo;
s->reply_queue_head = ldl_le_phys(s->producer_pa);
s->reply_queue_tail = ldl_le_phys(s->consumer_pa);
s->reply_queue_head = ldl_le_phys(&address_space_memory, s->producer_pa);
s->reply_queue_tail = ldl_le_phys(&address_space_memory, s->consumer_pa);
flags = le32_to_cpu(initq->flags);
if (flags & MFI_QUEUE_FLAG_CONTEXT64) {
s->flags |= MEGASAS_MASK_USE_QUEUE64;
Expand Down
3 changes: 2 additions & 1 deletion hw/scsi/vmw_pvscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
(sizeof(PVSCSICmdDescSetupRings)/sizeof(uint32_t))

#define RS_GET_FIELD(rs_pa, field) \
(ldl_le_phys(rs_pa + offsetof(struct PVSCSIRingsState, field)))
(ldl_le_phys(&address_space_memory, \
rs_pa + offsetof(struct PVSCSIRingsState, field)))
#define RS_SET_FIELD(rs_pa, field, val) \
(stl_le_phys(rs_pa + offsetof(struct PVSCSIRingsState, field), val))

Expand Down
3 changes: 2 additions & 1 deletion hw/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <inttypes.h>

#include "trace.h"
#include "exec/address-spaces.h"
#include "qemu/error-report.h"
#include "hw/virtio/virtio.h"
#include "qemu/atomic.h"
Expand Down Expand Up @@ -111,7 +112,7 @@ static inline uint32_t vring_desc_len(hwaddr desc_pa, int i)
{
hwaddr pa;
pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, len);
return ldl_phys(pa);
return ldl_phys(&address_space_memory, pa);
}

static inline uint16_t vring_desc_flags(hwaddr desc_pa, int i)
Expand Down
6 changes: 3 additions & 3 deletions include/exec/cpu-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ void qemu_flush_coalesced_mmio_buffer(void);
uint32_t ldub_phys(hwaddr addr);
uint32_t lduw_le_phys(hwaddr addr);
uint32_t lduw_be_phys(hwaddr addr);
uint32_t ldl_le_phys(hwaddr addr);
uint32_t ldl_be_phys(hwaddr addr);
uint32_t ldl_le_phys(AddressSpace *as, hwaddr addr);
uint32_t ldl_be_phys(AddressSpace *as, hwaddr addr);
uint64_t ldq_le_phys(hwaddr addr);
uint64_t ldq_be_phys(hwaddr addr);
void stb_phys(hwaddr addr, uint32_t val);
Expand All @@ -100,7 +100,7 @@ void stq_be_phys(hwaddr addr, uint64_t val);

#ifdef NEED_CPU_H
uint32_t lduw_phys(hwaddr addr);
uint32_t ldl_phys(hwaddr addr);
uint32_t ldl_phys(AddressSpace *as, hwaddr addr);
uint64_t ldq_phys(hwaddr addr);
void stl_phys_notdirty(hwaddr addr, uint32_t val);
void stw_phys(hwaddr addr, uint32_t val);
Expand Down
2 changes: 1 addition & 1 deletion include/hw/ppc/spapr.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static inline uint64_t ppc64_phys_to_real(uint64_t addr)

static inline uint32_t rtas_ld(target_ulong phys, int n)
{
return ldl_be_phys(ppc64_phys_to_real(phys + 4*n));
return ldl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n));
}

static inline void rtas_st(target_ulong phys, int n, uint32_t val)
Expand Down
2 changes: 1 addition & 1 deletion target-alpha/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ DEF_HELPER_FLAGS_2(ieee_input_cmp, TCG_CALL_NO_WG, void, env, i64)
DEF_HELPER_2(hw_ret, void, env, i64)
DEF_HELPER_3(call_pal, void, env, i64, i64)

DEF_HELPER_1(ldl_phys, i64, i64)
DEF_HELPER_2(ldl_phys, i64, env, i64)
DEF_HELPER_1(ldq_phys, i64, i64)
DEF_HELPER_2(ldl_l_phys, i64, env, i64)
DEF_HELPER_2(ldq_l_phys, i64, env, i64)
Expand Down
11 changes: 7 additions & 4 deletions target-alpha/mem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
/* Softmmu support */
#ifndef CONFIG_USER_ONLY

uint64_t helper_ldl_phys(uint64_t p)
uint64_t helper_ldl_phys(CPUAlphaState *env, uint64_t p)
{
return (int32_t)ldl_phys(p);
CPUState *cs = ENV_GET_CPU(env);
return (int32_t)ldl_phys(cs->as, p);
}

uint64_t helper_ldq_phys(uint64_t p)
Expand All @@ -36,8 +37,9 @@ uint64_t helper_ldq_phys(uint64_t p)

uint64_t helper_ldl_l_phys(CPUAlphaState *env, uint64_t p)
{
CPUState *cs = ENV_GET_CPU(env);
env->lock_addr = p;
return env->lock_value = (int32_t)ldl_phys(p);
return env->lock_value = (int32_t)ldl_phys(cs->as, p);
}

uint64_t helper_ldq_l_phys(CPUAlphaState *env, uint64_t p)
Expand All @@ -58,10 +60,11 @@ void helper_stq_phys(uint64_t p, uint64_t v)

uint64_t helper_stl_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
{
CPUState *cs = ENV_GET_CPU(env);
uint64_t ret = 0;

if (p == env->lock_addr) {
int32_t old = ldl_phys(p);
int32_t old = ldl_phys(cs->as, p);
if (old == (int32_t)env->lock_value) {
stl_phys(p, v);
ret = 1;
Expand Down
2 changes: 1 addition & 1 deletion target-alpha/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,7 @@ static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
switch ((insn >> 12) & 0xF) {
case 0x0:
/* Longword physical access (hw_ldl/p) */
gen_helper_ldl_phys(cpu_ir[ra], addr);
gen_helper_ldl_phys(cpu_ir[ra], cpu_env, addr);
break;
case 0x1:
/* Quadword physical access (hw_ldq/p) */
Expand Down
Loading

0 comments on commit fdfba1a

Please sign in to comment.