All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: jrossi@linux.ibm.com, qemu-devel@nongnu.org,
	qemu-s390x@nongnu.org, mst@redhat.com
Cc: jjherne@linux.ibm.com, alifm@linux.ibm.com, farman@linux.ibm.com,
	mjrosato@linux.ibm.com, zycai@linux.ibm.com
Subject: Re: [PATCH v4 10/15] pc-bios/s390-ccw: Introduce PCI device
Date: Wed, 4 Mar 2026 10:10:15 +0100	[thread overview]
Message-ID: <b88f3358-2c15-4430-8263-d4538df8e2be@redhat.com> (raw)
In-Reply-To: <20260304025917.2157032-11-jrossi@linux.ibm.com>

On 04/03/2026 03.59, jrossi@linux.ibm.com wrote:
> From: Jared Rossi <jrossi@linux.ibm.com>
> 
> Define selected s390x PCI instructions.
> 
> Signed-off-by: Jared Rossi <jrossi@linux.ibm.com>
> ---
...
> diff --git a/pc-bios/s390-ccw/pci.c b/pc-bios/s390-ccw/pci.c
> new file mode 100644
> index 0000000000..36e86fcc71
> --- /dev/null
> +++ b/pc-bios/s390-ccw/pci.c
> @@ -0,0 +1,118 @@
> +/*
> + * s390x PCI functionality
> + *
> + * Copyright 2025 IBM Corp.
> + * Author(s): Jared Rossi <jrossi@linux.ibm.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "clp.h"
> +#include "pci.h"
> +#include "bswap.h"
> +#include <stdio.h>
> +#include <stdbool.h>
> +
> +/* PCI load */
> +static inline int pcilg(uint64_t *data, uint64_t req, uint64_t offset,
> +                        uint8_t *status)
> +{
> +    union register_pair req_off = {.even = req, .odd = offset};
> +    int cc = -1;
> +    uint64_t __data;
> +
> +    asm volatile (
> +        "     .insn   rre,0xb9d20000,%[data],%[req_off]\n"
> +        "     ipm     %[cc]\n"
> +        "     srl     %[cc],28\n"
> +        : [cc] "+d" (cc), [data] "=d" (__data),
> +          [req_off] "+d" (req_off.pair) :: "cc");
> +    *status = req_off.even >> 24 & 0xff;
> +    *data = __data;
> +    return cc;
> +}
> +
> +/* PCI store */
> +static inline int pcistg(uint64_t data, uint64_t req, uint64_t offset,
> +                         uint8_t *status)
> +{
> +    union register_pair req_off = {.even = req, .odd = offset};
> +    int cc = -1;
> +
> +    asm volatile (
> +        "     .insn   rre,0xb9d00000,%[data],%[req_off]\n"
> +        "     ipm     %[cc]\n"
> +        "     srl     %[cc],28\n"
> +        : [cc] "+d" (cc), [req_off] "+d" (req_off.pair)
> +        : [data] "d" (data)
> +        : "cc");
> +    *status = req_off.even >> 24 & 0xff;
> +    return cc;
> +}
> +
> +int pci_write(uint32_t fhandle, uint64_t offset, uint8_t pcias, uint64_t data,
> +              uint8_t len)
> +{
> +
> +    uint64_t req = ZPCI_CREATE_REQ(fhandle, pcias, len);
> +    uint8_t status;
> +    int rc;
> +
> +    /* len must be non-zero power of 2 with a maximum of 8 bytes per write */
> +    switch (len) {
> +    case 1:
> +    case 2:
> +    case 4:
> +    case 8:
> +        rc = pcistg(data, req, offset, &status);
> +        break;
> +    default:
> +        return -1;
> +    }
> +
> +    /* Error condition detected */
> +    if (rc != 0) {
> +        printf("PCI store failed with status condition %d, return code %d\n",
> +               status, rc);
> +        return -1;

Here you already return -1 if rc != 0 ...

> +    }
> +
> +    return rc ? -1 : 0;

... so the check here is redundant. Please simply always return 0 here instead.

> +}
> +
> +int pci_read(uint32_t fhandle, uint64_t offset, uint8_t pcias, void *buf,
> +             uint8_t len)
> +{
> +    uint64_t req, data;
> +    uint8_t status;
> +    int rc;
> +
> +    req = ZPCI_CREATE_REQ(fhandle, pcias, len);
> +    rc = pcilg(&data, req, offset, &status);
> +
> +    /* Error condition detected */
> +    if (rc != 0) {
> +        printf("PCI load failed with status condition %d, return code %d\n",
> +               status, rc);
> +        return -1;
> +    }
> +
> +    switch (len) {
> +    case 1:
> +        *(uint8_t *)buf = data;
> +        break;
> +    case 2:
> +        *(uint16_t *)buf = data;
> +        break;
> +    case 4:
> +        *(uint32_t *)buf = data;
> +        break;
> +    case 8:
> +        *(uint64_t *)buf = data;
> +        break;
> +    default:
> +        return -1;
> +    }
> +
> +    return rc ? -1 : 0;

dito, you checked for rc != 0 already earlier in this function.

  Thomas



  reply	other threads:[~2026-03-04  9:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04  2:59 [PATCH v4 00/15] s390x: Add support for virtio-blk-pci IPL device jrossi
2026-03-04  2:59 ` [PATCH v4 01/15] pc-bios/s390-ccw: Fix misattributed function prototypes jrossi
2026-03-04  2:59 ` [PATCH v4 02/15] pc-bios/s390-ccw: Remove redundant vring schid attribute jrossi
2026-03-04  2:59 ` [PATCH v4 03/15] pc-bios/s390-ccw: Always reset virtio device on failed boot attempt jrossi
2026-03-04  8:23   ` Thomas Huth
2026-03-04 13:39   ` Eric Farman
2026-03-04  2:59 ` [PATCH v4 04/15] s390x: Remove duplicate definitions of IPL types jrossi
2026-03-04  8:34   ` Thomas Huth
2026-03-04  2:59 ` [PATCH v4 05/15] pc-bios/s390-ccw: Store device type independent of sense data jrossi
2026-03-04  2:59 ` [PATCH v4 06/15] pc-bios/s390-ccw: Split virtio-ccw and generic virtio jrossi
2026-03-04  8:42   ` Thomas Huth
2026-03-05 15:43   ` Eric Farman
2026-03-04  2:59 ` [PATCH v4 07/15] include/hw/s390x: Move CLP definitions for easier BIOS access jrossi
2026-03-04  2:59 ` [PATCH v4 08/15] pc-bios/s390-ccw: Introduce CLP Architecture jrossi
2026-03-04 14:05   ` Eric Farman
2026-03-04  2:59 ` [PATCH v4 09/15] s390x: Add definitions for PCI IPL type jrossi
2026-03-04  2:59 ` [PATCH v4 10/15] pc-bios/s390-ccw: Introduce PCI device jrossi
2026-03-04  9:10   ` Thomas Huth [this message]
2026-03-04 14:35     ` Jared Rossi
2026-03-04  2:59 ` [PATCH v4 11/15] pc-bios/s390-ccw: Introduce virtio-pci functions jrossi
2026-03-04  9:18   ` Thomas Huth
2026-03-04 14:38     ` Jared Rossi
2026-03-05 18:37   ` Eric Farman
2026-03-04  2:59 ` [PATCH v4 12/15] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL jrossi
2026-03-04  9:53   ` Thomas Huth
2026-03-04 14:29     ` Jared Rossi
2026-03-04 14:39       ` Thomas Huth
2026-03-04 20:17         ` Jared Rossi
2026-03-05  6:16           ` Thomas Huth
2026-03-05 22:25   ` Eric Farman
2026-03-04  2:59 ` [PATCH v4 13/15] s390x: Build IPLB for virtio-pci devices jrossi
2026-03-05 22:30   ` Eric Farman
2026-03-04  2:59 ` [PATCH v4 14/15] hw: Add "loadparm" property to virtio block PCI devices booting on s390x jrossi
2026-03-04  9:59   ` Thomas Huth
2026-03-04  2:59 ` [PATCH v4 15/15] tests/qtest: Add s390x PCI boot test to cdrom-test.c jrossi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b88f3358-2c15-4430-8263-d4538df8e2be@redhat.com \
    --to=thuth@redhat.com \
    --cc=alifm@linux.ibm.com \
    --cc=farman@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=jrossi@linux.ibm.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=zycai@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.