Skip to content

Commit 4a63054

Browse files
committedDec 31, 2021
pci: Let ld*_pci_dma() propagate MemTxResult
ld*_dma() returns a MemTxResult type. Do not discard it, return it to the caller. Update the few callers. Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]>
1 parent 6bebb27 commit 4a63054

File tree

7 files changed

+60
-53
lines changed

7 files changed

+60
-53
lines changed
 

‎hw/audio/intel-hda.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void intel_hda_corb_run(IntelHDAState *d)
335335

336336
rp = (d->corb_rp + 1) & 0xff;
337337
addr = intel_hda_addr(d->corb_lbase, d->corb_ubase);
338-
verb = ldl_le_pci_dma(&d->pci, addr + 4 * rp, MEMTXATTRS_UNSPECIFIED);
338+
ldl_le_pci_dma(&d->pci, addr + 4 * rp, &verb, MEMTXATTRS_UNSPECIFIED);
339339
d->corb_rp = rp;
340340

341341
dprint(d, 2, "%s: [rp 0x%x] verb 0x%08x\n", __func__, rp, verb);

‎hw/net/eepro100.c

+10-15
Original file line numberDiff line numberDiff line change
@@ -769,18 +769,16 @@ static void tx_command(EEPRO100State *s)
769769
} else {
770770
/* Flexible mode. */
771771
uint8_t tbd_count = 0;
772+
uint32_t tx_buffer_address;
773+
uint16_t tx_buffer_size;
774+
uint16_t tx_buffer_el;
775+
772776
if (s->has_extended_tcb_support && !(s->configuration[6] & BIT(4))) {
773777
/* Extended Flexible TCB. */
774778
for (; tbd_count < 2; tbd_count++) {
775-
uint32_t tx_buffer_address = ldl_le_pci_dma(&s->dev,
776-
tbd_address,
777-
attrs);
778-
uint16_t tx_buffer_size = lduw_le_pci_dma(&s->dev,
779-
tbd_address + 4,
780-
attrs);
781-
uint16_t tx_buffer_el = lduw_le_pci_dma(&s->dev,
782-
tbd_address + 6,
783-
attrs);
779+
ldl_le_pci_dma(&s->dev, tbd_address, &tx_buffer_address, attrs);
780+
lduw_le_pci_dma(&s->dev, tbd_address + 4, &tx_buffer_size, attrs);
781+
lduw_le_pci_dma(&s->dev, tbd_address + 6, &tx_buffer_el, attrs);
784782
tbd_address += 8;
785783
TRACE(RXTX, logout
786784
("TBD (extended flexible mode): buffer address 0x%08x, size 0x%04x\n",
@@ -796,12 +794,9 @@ static void tx_command(EEPRO100State *s)
796794
}
797795
tbd_address = tbd_array;
798796
for (; tbd_count < s->tx.tbd_count; tbd_count++) {
799-
uint32_t tx_buffer_address = ldl_le_pci_dma(&s->dev, tbd_address,
800-
attrs);
801-
uint16_t tx_buffer_size = lduw_le_pci_dma(&s->dev, tbd_address + 4,
802-
attrs);
803-
uint16_t tx_buffer_el = lduw_le_pci_dma(&s->dev, tbd_address + 6,
804-
attrs);
797+
ldl_le_pci_dma(&s->dev, tbd_address, &tx_buffer_address, attrs);
798+
lduw_le_pci_dma(&s->dev, tbd_address + 4, &tx_buffer_size, attrs);
799+
lduw_le_pci_dma(&s->dev, tbd_address + 6, &tx_buffer_el, attrs);
805800
tbd_address += 8;
806801
TRACE(RXTX, logout
807802
("TBD (flexible mode): buffer address 0x%08x, size 0x%04x\n",

‎hw/net/tulip.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ static void tulip_desc_read(TULIPState *s, hwaddr p,
7373
const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
7474

7575
if (s->csr[0] & CSR0_DBO) {
76-
desc->status = ldl_be_pci_dma(&s->dev, p, attrs);
77-
desc->control = ldl_be_pci_dma(&s->dev, p + 4, attrs);
78-
desc->buf_addr1 = ldl_be_pci_dma(&s->dev, p + 8, attrs);
79-
desc->buf_addr2 = ldl_be_pci_dma(&s->dev, p + 12, attrs);
76+
ldl_be_pci_dma(&s->dev, p, &desc->status, attrs);
77+
ldl_be_pci_dma(&s->dev, p + 4, &desc->control, attrs);
78+
ldl_be_pci_dma(&s->dev, p + 8, &desc->buf_addr1, attrs);
79+
ldl_be_pci_dma(&s->dev, p + 12, &desc->buf_addr2, attrs);
8080
} else {
81-
desc->status = ldl_le_pci_dma(&s->dev, p, attrs);
82-
desc->control = ldl_le_pci_dma(&s->dev, p + 4, attrs);
83-
desc->buf_addr1 = ldl_le_pci_dma(&s->dev, p + 8, attrs);
84-
desc->buf_addr2 = ldl_le_pci_dma(&s->dev, p + 12, attrs);
81+
ldl_le_pci_dma(&s->dev, p, &desc->status, attrs);
82+
ldl_le_pci_dma(&s->dev, p + 4, &desc->control, attrs);
83+
ldl_le_pci_dma(&s->dev, p + 8, &desc->buf_addr1, attrs);
84+
ldl_le_pci_dma(&s->dev, p + 12, &desc->buf_addr2, attrs);
8585
}
8686
}
8787

‎hw/scsi/megasas.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,12 @@ static uint64_t megasas_frame_get_context(MegasasState *s,
202202
unsigned long frame)
203203
{
204204
PCIDevice *pci = &s->parent_obj;
205-
return ldq_le_pci_dma(pci,
206-
frame + offsetof(struct mfi_frame_header, context),
207-
MEMTXATTRS_UNSPECIFIED);
205+
uint64_t val;
206+
207+
ldq_le_pci_dma(pci, frame + offsetof(struct mfi_frame_header, context),
208+
&val, MEMTXATTRS_UNSPECIFIED);
209+
210+
return val;
208211
}
209212

210213
static bool megasas_frame_is_ieee_sgl(MegasasCmd *cmd)
@@ -536,8 +539,8 @@ static MegasasCmd *megasas_enqueue_frame(MegasasState *s,
536539
s->busy++;
537540

538541
if (s->consumer_pa) {
539-
s->reply_queue_tail = ldl_le_pci_dma(pcid, s->consumer_pa,
540-
MEMTXATTRS_UNSPECIFIED);
542+
ldl_le_pci_dma(pcid, s->consumer_pa, &s->reply_queue_tail,
543+
MEMTXATTRS_UNSPECIFIED);
541544
}
542545
trace_megasas_qf_enqueue(cmd->index, cmd->count, cmd->context,
543546
s->reply_queue_head, s->reply_queue_tail, s->busy);
@@ -568,14 +571,14 @@ static void megasas_complete_frame(MegasasState *s, uint64_t context)
568571
stl_le_pci_dma(pci_dev, s->reply_queue_pa + queue_offset,
569572
context, attrs);
570573
}
571-
s->reply_queue_tail = ldl_le_pci_dma(pci_dev, s->consumer_pa, attrs);
574+
ldl_le_pci_dma(pci_dev, s->consumer_pa, &s->reply_queue_tail, attrs);
572575
trace_megasas_qf_complete(context, s->reply_queue_head,
573576
s->reply_queue_tail, s->busy);
574577
}
575578

576579
if (megasas_intr_enabled(s)) {
577580
/* Update reply queue pointer */
578-
s->reply_queue_tail = ldl_le_pci_dma(pci_dev, s->consumer_pa, attrs);
581+
ldl_le_pci_dma(pci_dev, s->consumer_pa, &s->reply_queue_tail, attrs);
579582
tail = s->reply_queue_head;
580583
s->reply_queue_head = megasas_next_index(s, tail, s->fw_cmds);
581584
trace_megasas_qf_update(s->reply_queue_head, s->reply_queue_tail,
@@ -679,9 +682,9 @@ static int megasas_init_firmware(MegasasState *s, MegasasCmd *cmd)
679682
pa_lo = le32_to_cpu(initq->pi_addr_lo);
680683
pa_hi = le32_to_cpu(initq->pi_addr_hi);
681684
s->producer_pa = ((uint64_t) pa_hi << 32) | pa_lo;
682-
s->reply_queue_head = ldl_le_pci_dma(pcid, s->producer_pa, attrs);
685+
ldl_le_pci_dma(pcid, s->producer_pa, &s->reply_queue_head, attrs);
683686
s->reply_queue_head %= MEGASAS_MAX_FRAMES;
684-
s->reply_queue_tail = ldl_le_pci_dma(pcid, s->consumer_pa, attrs);
687+
ldl_le_pci_dma(pcid, s->consumer_pa, &s->reply_queue_tail, attrs);
685688
s->reply_queue_tail %= MEGASAS_MAX_FRAMES;
686689
flags = le32_to_cpu(initq->flags);
687690
if (flags & MFI_QUEUE_FLAG_CONTEXT64) {

‎hw/scsi/mptsas.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,16 @@ static dma_addr_t mptsas_ld_sg_base(MPTSASState *s, uint32_t flags_and_length,
177177
dma_addr_t addr;
178178

179179
if (flags_and_length & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
180-
addr = ldq_le_pci_dma(pci, *sgaddr + 4, attrs);
180+
uint64_t addr64;
181+
182+
ldq_le_pci_dma(pci, *sgaddr + 4, &addr64, attrs);
183+
addr = addr64;
181184
*sgaddr += 12;
182185
} else {
183-
addr = ldl_le_pci_dma(pci, *sgaddr + 4, attrs);
186+
uint32_t addr32;
187+
188+
ldl_le_pci_dma(pci, *sgaddr + 4, &addr32, attrs);
189+
addr = addr32;
184190
*sgaddr += 8;
185191
}
186192
return addr;
@@ -204,7 +210,7 @@ static int mptsas_build_sgl(MPTSASState *s, MPTSASRequest *req, hwaddr addr)
204210
dma_addr_t addr, len;
205211
uint32_t flags_and_length;
206212

207-
flags_and_length = ldl_le_pci_dma(pci, sgaddr, MEMTXATTRS_UNSPECIFIED);
213+
ldl_le_pci_dma(pci, sgaddr, &flags_and_length, MEMTXATTRS_UNSPECIFIED);
208214
len = flags_and_length & MPI_SGE_LENGTH_MASK;
209215
if ((flags_and_length & MPI_SGE_FLAGS_ELEMENT_TYPE_MASK)
210216
!= MPI_SGE_FLAGS_SIMPLE_ELEMENT ||
@@ -235,8 +241,8 @@ static int mptsas_build_sgl(MPTSASState *s, MPTSASRequest *req, hwaddr addr)
235241
break;
236242
}
237243

238-
flags_and_length = ldl_le_pci_dma(pci, next_chain_addr,
239-
MEMTXATTRS_UNSPECIFIED);
244+
ldl_le_pci_dma(pci, next_chain_addr, &flags_and_length,
245+
MEMTXATTRS_UNSPECIFIED);
240246
if ((flags_and_length & MPI_SGE_FLAGS_ELEMENT_TYPE_MASK)
241247
!= MPI_SGE_FLAGS_CHAIN_ELEMENT) {
242248
return MPI_IOCSTATUS_INVALID_SGL;

‎hw/scsi/vmw_pvscsi.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
#define PVSCSI_MAX_CMD_DATA_WORDS \
5151
(sizeof(PVSCSICmdDescSetupRings)/sizeof(uint32_t))
5252

53-
#define RS_GET_FIELD(m, field) \
54-
(ldl_le_pci_dma(&container_of(m, PVSCSIState, rings)->parent_obj, \
53+
#define RS_GET_FIELD(pval, m, field) \
54+
ldl_le_pci_dma(&container_of(m, PVSCSIState, rings)->parent_obj, \
5555
(m)->rs_pa + offsetof(struct PVSCSIRingsState, field), \
56-
MEMTXATTRS_UNSPECIFIED))
56+
pval, MEMTXATTRS_UNSPECIFIED)
5757
#define RS_SET_FIELD(m, field, val) \
5858
(stl_le_pci_dma(&container_of(m, PVSCSIState, rings)->parent_obj, \
5959
(m)->rs_pa + offsetof(struct PVSCSIRingsState, field), val, \
@@ -249,10 +249,11 @@ pvscsi_ring_cleanup(PVSCSIRingInfo *mgr)
249249
static hwaddr
250250
pvscsi_ring_pop_req_descr(PVSCSIRingInfo *mgr)
251251
{
252-
uint32_t ready_ptr = RS_GET_FIELD(mgr, reqProdIdx);
252+
uint32_t ready_ptr;
253253
uint32_t ring_size = PVSCSI_MAX_NUM_PAGES_REQ_RING
254254
* PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
255255

256+
RS_GET_FIELD(&ready_ptr, mgr, reqProdIdx);
256257
if (ready_ptr != mgr->consumed_ptr
257258
&& ready_ptr - mgr->consumed_ptr < ring_size) {
258259
uint32_t next_ready_ptr =
@@ -323,8 +324,11 @@ pvscsi_ring_flush_cmp(PVSCSIRingInfo *mgr)
323324
static bool
324325
pvscsi_ring_msg_has_room(PVSCSIRingInfo *mgr)
325326
{
326-
uint32_t prodIdx = RS_GET_FIELD(mgr, msgProdIdx);
327-
uint32_t consIdx = RS_GET_FIELD(mgr, msgConsIdx);
327+
uint32_t prodIdx;
328+
uint32_t consIdx;
329+
330+
RS_GET_FIELD(&prodIdx, mgr, msgProdIdx);
331+
RS_GET_FIELD(&consIdx, mgr, msgConsIdx);
328332

329333
return (prodIdx - consIdx) < (mgr->msg_len_mask + 1);
330334
}

‎include/hw/pci/pci.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -850,15 +850,14 @@ static inline MemTxResult pci_dma_write(PCIDevice *dev, dma_addr_t addr,
850850
DMA_DIRECTION_FROM_DEVICE, MEMTXATTRS_UNSPECIFIED);
851851
}
852852

853-
#define PCI_DMA_DEFINE_LDST(_l, _s, _bits) \
854-
static inline uint##_bits##_t ld##_l##_pci_dma(PCIDevice *dev, \
855-
dma_addr_t addr, \
856-
MemTxAttrs attrs) \
857-
{ \
858-
uint##_bits##_t val; \
859-
ld##_l##_dma(pci_get_address_space(dev), addr, &val, attrs); \
860-
return val; \
861-
} \
853+
#define PCI_DMA_DEFINE_LDST(_l, _s, _bits) \
854+
static inline MemTxResult ld##_l##_pci_dma(PCIDevice *dev, \
855+
dma_addr_t addr, \
856+
uint##_bits##_t *val, \
857+
MemTxAttrs attrs) \
858+
{ \
859+
return ld##_l##_dma(pci_get_address_space(dev), addr, val, attrs); \
860+
} \
862861
static inline MemTxResult st##_s##_pci_dma(PCIDevice *dev, \
863862
dma_addr_t addr, \
864863
uint##_bits##_t val, \

0 commit comments

Comments
 (0)
Please sign in to comment.