qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jared Rossi <jrossi@linux.ibm.com>
To: Farhan Ali <alifm@linux.ibm.com>,
	qemu-devel@nongnu.org, qemu-s390x@nongnu.org, thuth@redhat.com
Cc: jjherne@linux.ibm.com, farman@linux.ibm.com,
	mjrosato@linux.ibm.com, zycai@linux.ibm.com
Subject: Re: [PATCH 4/7] pc-bios/s390-ccw: Introduce PCI device IPL format
Date: Thu, 23 Oct 2025 14:19:28 -0400	[thread overview]
Message-ID: <62ab7aaa-212a-4f27-b70d-989ae54bbfaf@linux.ibm.com> (raw)
In-Reply-To: <49301ff9-894c-4341-bd9e-7b2213aa184b@linux.ibm.com>

Thanks Farhan,

On 10/23/25 1:31 PM, Farhan Ali wrote:
> [snip]
>> +
>> +int pci_write(uint32_t fhandle, uint64_t offset, uint64_t data, 
>> uint8_t len)
>> +{
>> +
>> +    uint64_t req = ZPCI_CREATE_REQ(fhandle, 4, len);
>
> This assumes that we will only read to BAR 4? I think we should pass 
> the PCIAS here as well if we want to generalize this function?
I was thinking about this too and I agree that it should be 
generalized.  Also when reading the capabilities from the configuration 
space, I did not check that the location is, actually, BAR 4.  I will 
generalize the functions so that we do not make any assumptions about BAR 4.

>
>> +    uint8_t status;
>> +    int rc;
>> +
>> +    rc = pcistg(data, req, offset, &status);
>> +    if (rc == 1) {
>> +        return status;
>> +    } else if (rc) {
>> +        return rc;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +int pci_read(uint32_t fhandle, uint64_t offset, uint8_t picas, void 
>> *buf, uint8_t len)
>> +{
>> +    uint64_t req;
>> +    uint64_t data;
>> +    uint8_t status;
>> +    int readlen;
>> +    int i = 0;
>> +    int rc = 0;
>> +
>> +    while (len > 0 && !rc) {
>> +        data = 0;
>> +        readlen = len > 8 ? 8 : len;
>> +        req = ZPCI_CREATE_REQ(fhandle, picas, readlen);
>> +        rc = pcilg(&data, req, offset + (i * 8), &status);
>
> Shouldn't this be offset + (i * readlen)? but I guess this works 
> because we will only increment i on reads greater than 8 bytes. Maybe 
> we could try to simplify this and have a single pci_read function and 
> several other helper functions that uses pci_read to read sizes of 
> 1/2/4/8 bytes. For reads greater than 8 bytes we can have another 
> function (similar to zpci_memcpy_from_io, in the kernel). From what I 
> can tell most of the pci_read calls reads are 8 bytes in the rest of 
> the patches, except maybe for one case which reads greater than 8?
Yes I agree.  Thomas mentioned something similar.  I think using some 
helper functions will make the code easier to read also.

>
>> +        ((uint64_t *)buf)[i] = data;
>> +        len -= readlen;
>> +        i++;
>> +    }
>> +
>> +    if (rc == 1) {
>> +        return status;
>> +    } else if (rc) {
>> +        return rc;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +/*
>> + * Find the position of the capability config within PCI configuration
>> + * space for a given cfg type.  Return the position if found, 
>> otherwise 0.
>> + */
>> +uint8_t find_cap_pos(uint32_t fhandle, uint64_t cfg_type) {
>> +    uint64_t req, next, cfg;
>> +    uint8_t status;
>> +    int rc;
>> +
>> +    req = ZPCI_CREATE_REQ(fhandle, 0xf, 1);
>> +    rc = pcilg(&next, req, PCI_CAPABILITY_LIST, &status);
>> +    rc = pcilg(&cfg, req, next + 3, &status);
>
> Why are we reading next + 3 into cfg? If I understand this correctly 
> next will be the address of the first capability in the linked list, 
> and so we should just read the first byte from next to get the 
> capability id? I think we should have helper function like 
> qpci_find_capability to find the capabilities?
>
>
>> +
>> +    while (!rc && (cfg != cfg_type) && next) {
>> +        rc = pcilg(&next, req, next + 1, &status);
>> +        rc = pcilg(&cfg, req, next + 3, &status);
>
> Same question here?
I see you already answered this yourself in a follow-up mail, but you 
are correct that this is for the vendor-specific capabilities. I will 
move it to virtio-pci.c and add a comment for clarity.

>
>> +    }
>> +
>> +    return rc ? 0 : next;
>> +}
>> +
>
> [..snip..]
>

Regards,
Jared Rossi


  parent reply	other threads:[~2025-10-23 18:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 16:20 [PATCH 0/7] s390x: Add support for virtio-blk-pci IPL device jrossi
2025-10-20 16:20 ` [PATCH 1/7] pc-bios/s390-ccw: Fix Misattributed Function Prototypes jrossi
2025-10-20 16:50   ` Thomas Huth
2025-10-20 18:57     ` Jared Rossi
2025-10-20 16:20 ` [PATCH 2/7] pc-bios/s390-ccw: Split virtio-ccw and generic virtio jrossi
2025-10-21  9:23   ` Thomas Huth
2025-10-22 19:44     ` Jared Rossi
2025-10-20 16:20 ` [PATCH 3/7] pc-bios/s390-ccw: Introduce CLP Architecture jrossi
2025-10-21  5:24   ` Thomas Huth
2025-10-21  9:30   ` Thomas Huth
2025-10-20 16:20 ` [PATCH 4/7] pc-bios/s390-ccw: Introduce PCI device IPL format jrossi
2025-10-21  6:42   ` Thomas Huth
2025-10-23 17:31   ` Farhan Ali
2025-10-23 17:56     ` Farhan Ali
2025-10-23 18:19     ` Jared Rossi [this message]
2025-10-20 16:20 ` [PATCH 5/7] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL jrossi
2025-10-21 11:11   ` Thomas Huth
2025-10-22 16:40   ` Zhuoying Cai
2025-10-22 18:57     ` Jared Rossi
2025-10-23 18:16   ` Farhan Ali
2025-10-20 16:20 ` [PATCH 6/7] s390x: Build IPLB for virtio-pci devices jrossi
2025-10-21 14:08   ` Thomas Huth
2025-10-22 19:35     ` Jared Rossi
2025-10-20 16:20 ` [PATCH 7/7] tests/qtest: Add s390x PCI boot test to cdrom-test.c jrossi
2025-10-21 14:09   ` Thomas Huth

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=62ab7aaa-212a-4f27-b70d-989ae54bbfaf@linux.ibm.com \
    --to=jrossi@linux.ibm.com \
    --cc=alifm@linux.ibm.com \
    --cc=farman@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=thuth@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).