QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
From: Muzammil Ashraf <m.muzzammilashraf@gmail.com>
To: Aditya Gupta <adityag@linux.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: PCIE Memory Information
Date: Sun, 5 May 2024 22:19:41 +0500	[thread overview]
Message-ID: <CAJHePoZiH6eTWJNASrk_0Fm4iEhqJfskCr6StToY2Xy6BFXB6A@mail.gmail.com> (raw)
In-Reply-To: <1a1f5642-fc0e-4d1f-bc29-66da97cccd1e@linux.ibm.com>

I have already studied this document and tested the overlap of MemoryRegions.

There is a structure named PCIHostState and in this struct there is a
field named config_reg. I want to understand where it gets changed.

On Sun, May 5, 2024 at 6:45 PM Aditya Gupta <adityag@linux.ibm.com> wrote:
>
> Hi Ashraf,
>
> On 04/05/24 12:45, Muzammil Ashraf wrote:
>
> Hi All,
>
> I am debugging a PCI subsystem. I saw callbacks registered here to
> catch the pcie config read/write request at hw/pci/pci_host.c:201. How
> can I make my subregion to overlap this area and How to receive those
> pcie config read/write requests to my callbacks?
>
>
> Can go through this doc: https://www.qemu.org/docs/master/devel/memory.html#overlapping-regions-and-priority
>
> Normally the callbacks you mentioned will be registered on a MemoryRegion. You can create your own MemoryRegion, and set your custom .read, .write callbacks.
>
> And setting the MemoryRegion's priority as a big positive number.
>
>
> FWIW, had did something like this in past:
>
>
> +static uint64_t adi_region_read(void *chip10, hwaddr addr, unsigned size) {
> + // your code
> +}
> +
> +static void adi_region_write(void *chip10, hwaddr addr, uint64_t value, unsigned size) {
> + // your code
> +}
> +
> +static const MemoryRegionOps adi_region_ops = {
> +    .read = adi_region_read,
> +    .write = adi_region_write,
> +        .endianness = DEVICE_BIG_ENDIAN,
> +    .impl = {
> +        .min_access_size = 4,
> +        .max_access_size = 4,
> +    },
> +};
> +
>
> +    static hwaddr ADI_REGION_BASE = 0x0006010000000000ull + 0x100;
> +
>
> +    memory_region_init_io(&chip10->adi_region, OBJECT(chip10), &adi_region_ops, chip10, "custom region: adityag", 0x100);
> +    memory_region_add_subregion(get_system_memory(), ADI_REGION_BASE, &chip10->adi_region);
>
> Instead of 'get_system_memory', you will have to see what is the PCI config region a subregion of.
>
>
> Then, set the MemoryRegion's priority to some big number.
>
> Then, you can verify if your overlapping was successful, with something like this:
>
>
> +    MemoryRegion *mr = address_space_translate(&address_space_memory, ADI_REGION_BASE, &xlat, &l, false, MEMTXATTRS_UNSPECIFIED);
>
> or
>
> +    cpu_physical_memory_read(ADI_REGION_BASE, &val, 4);
>
>
> 1st should return your MemoryRegion, and second one should call your .read callback.
>
>
> Thanks,
>
> Aditya Gupta


      reply	other threads:[~2024-05-05 17:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-04  7:15 PCIE Memory Information Muzammil Ashraf
2024-05-05 13:45 ` Aditya Gupta
2024-05-05 17:19   ` Muzammil Ashraf [this message]

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=CAJHePoZiH6eTWJNASrk_0Fm4iEhqJfskCr6StToY2Xy6BFXB6A@mail.gmail.com \
    --to=m.muzzammilashraf@gmail.com \
    --cc=adityag@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).