qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aditya Gupta <adityag@linux.ibm.com>
To: Muzammil Ashraf <m.muzzammilashraf@gmail.com>, qemu-devel@nongnu.org
Subject: Re: PCIE Memory Information
Date: Sun, 5 May 2024 19:15:03 +0530	[thread overview]
Message-ID: <1a1f5642-fc0e-4d1f-bc29-66da97cccd1e@linux.ibm.com> (raw)
In-Reply-To: <CAJHePoZ=+vJt_8CC3eYN5kjfUcqQMRjnzM+xEfoBswq8-8JWfQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2062 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3327 bytes --]

  reply	other threads:[~2024-05-05 13:45 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 [this message]
2024-05-05 17:19   ` Muzammil Ashraf

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=1a1f5642-fc0e-4d1f-bc29-66da97cccd1e@linux.ibm.com \
    --to=adityag@linux.ibm.com \
    --cc=m.muzzammilashraf@gmail.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 NNTP newsgroup(s).