All of lore.kernel.org
 help / color / mirror / Atom feed
* Adding IO memory region to mipssim
@ 2021-09-10 13:21 Hinko Kocevar
  2021-09-10 15:30 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 3+ messages in thread
From: Hinko Kocevar @ 2021-09-10 13:21 UTC (permalink / raw)
  To: qemu-devel

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

I'm trying to add an I/O memory region to mipssim machine to emulate a MMIO
region used by the u-boot loaded as BIOS image. I can confirm that the
machine starts and loads the BIOS, starts execution but hangs due to
unhandled IO access as described below.

The region should be at 0xB8810000, of size 0x10000.

I've added these lines of code to mispsim.c mips_mipssim_init():

    my_state *s = g_malloc0(sizeof(my_state));
    memory_region_init_io(&s->mmio, NULL, &my_ops, s,
                         "mips_mipssim.foo", 0x10000);
    memory_region_add_subregion(address_space_mem, 0xB8810000LL, &s->mmio);

All goes well, the machine starts, and I can see the newly added region in
qemu monitor info mtree output like so:

    00000000b8810000-00000000b881ffff (prio 0, i/o): mips_mipssim.foo

With some tracing enabled I see this error:

 Invalid access at addr 0x18810104, size 4, region '(null)', reason:
rejected

I know the u-boot is making request to 0xB8810104 and not 0x18810104. I
also can see 0xB8810104 address being handed to io_writex(), but mr_offset
becomes 0x18810104 here:

  mr_offset = (iotlbentry->addr & TARGET_PAGE_MASK) + addr;

What is going on?

FWIW, I can place my emulated memory region at 0x18810104, but would like
to understand the behavior above.

Thanks!
//hinko

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Adding IO memory region to mipssim
  2021-09-10 13:21 Adding IO memory region to mipssim Hinko Kocevar
@ 2021-09-10 15:30 ` Philippe Mathieu-Daudé
  2021-09-10 19:25   ` Hinko Kocevar
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-10 15:30 UTC (permalink / raw)
  To: Hinko Kocevar, qemu-devel

On 9/10/21 3:21 PM, Hinko Kocevar wrote:
> I'm trying to add an I/O memory region to mipssim machine to emulate a
> MMIO region used by the u-boot loaded as BIOS image. I can confirm that
> the machine starts and loads the BIOS, starts execution but hangs due to
> unhandled IO access as described below.
> 
> The region should be at 0xB8810000, of size 0x10000.
> 
> I've added these lines of code to mispsim.c mips_mipssim_init():
> 
>     my_state *s = g_malloc0(sizeof(my_state));
>     memory_region_init_io(&s->mmio, NULL, &my_ops, s,
>                          "mips_mipssim.foo", 0x10000);
>     memory_region_add_subregion(address_space_mem, 0xB8810000LL, &s->mmio);

You need to map your device at its physical address, not the virtual
one.

> All goes well, the machine starts, and I can see the newly added region
> in qemu monitor info mtree output like so:
> 
>     00000000b8810000-00000000b881ffff (prio 0, i/o): mips_mipssim.foo
> 
> With some tracing enabled I see this error:
> 
>  Invalid access at addr 0x18810104, size 4, region '(null)', reason:
> rejected
> 
> I know the u-boot is making request to 0xB8810104 and not 0x18810104. I

U-boot accessed the virtual address which is resolved into the physical
one (where your device should be mapped).

> also can see 0xB8810104 address being handed to io_writex(), but
> mr_offset becomes 0x18810104 here:
> 
>   mr_offset = (iotlbentry->addr & TARGET_PAGE_MASK) + addr;
> 
> What is going on?
> 
> FWIW, I can place my emulated memory region at 0x18810104, but would
> like to understand the behavior above.

Yes, this is the correct address to map it.

Maybe this helps:
https://training.mips.com/basic_mips/PDF/Memory_Map.pdf

Regards,

Phil.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Adding IO memory region to mipssim
  2021-09-10 15:30 ` Philippe Mathieu-Daudé
@ 2021-09-10 19:25   ` Hinko Kocevar
  0 siblings, 0 replies; 3+ messages in thread
From: Hinko Kocevar @ 2021-09-10 19:25 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel

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

Got it Phil, thank you very much! I need to educate myself on the subject
of TLB and MMU for mips.
//hinko

On Fri, Sep 10, 2021 at 5:30 PM Philippe Mathieu-Daudé <f4bug@amsat.org>
wrote:

> On 9/10/21 3:21 PM, Hinko Kocevar wrote:
> > I'm trying to add an I/O memory region to mipssim machine to emulate a
> > MMIO region used by the u-boot loaded as BIOS image. I can confirm that
> > the machine starts and loads the BIOS, starts execution but hangs due to
> > unhandled IO access as described below.
> >
> > The region should be at 0xB8810000, of size 0x10000.
> >
> > I've added these lines of code to mispsim.c mips_mipssim_init():
> >
> >     my_state *s = g_malloc0(sizeof(my_state));
> >     memory_region_init_io(&s->mmio, NULL, &my_ops, s,
> >                          "mips_mipssim.foo", 0x10000);
> >     memory_region_add_subregion(address_space_mem, 0xB8810000LL,
> &s->mmio);
>
> You need to map your device at its physical address, not the virtual
> one.
>
> > All goes well, the machine starts, and I can see the newly added region
> > in qemu monitor info mtree output like so:
> >
> >     00000000b8810000-00000000b881ffff (prio 0, i/o): mips_mipssim.foo
> >
> > With some tracing enabled I see this error:
> >
> >  Invalid access at addr 0x18810104, size 4, region '(null)', reason:
> > rejected
> >
> > I know the u-boot is making request to 0xB8810104 and not 0x18810104. I
>
> U-boot accessed the virtual address which is resolved into the physical
> one (where your device should be mapped).
>
> > also can see 0xB8810104 address being handed to io_writex(), but
> > mr_offset becomes 0x18810104 here:
> >
> >   mr_offset = (iotlbentry->addr & TARGET_PAGE_MASK) + addr;
> >
> > What is going on?
> >
> > FWIW, I can place my emulated memory region at 0x18810104, but would
> > like to understand the behavior above.
>
> Yes, this is the correct address to map it.
>
> Maybe this helps:
> https://training.mips.com/basic_mips/PDF/Memory_Map.pdf
>
> Regards,
>
> Phil.
>


-- 
.. the more I see the less I believe.., AE AoR

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-10 19:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10 13:21 Adding IO memory region to mipssim Hinko Kocevar
2021-09-10 15:30 ` Philippe Mathieu-Daudé
2021-09-10 19:25   ` Hinko Kocevar

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.