On Fri, Jun 30, 2023 at 01:37:49AM +0200, BALATON Zoltan wrote: > Hello, > > Some devices have bits that allow the guest to change endianness of memory > mapped resources, e.g. ati-vga should allow switching the regs BAR into big > endian on writing a bit. What's the best way to emulate this? > > The naive way could be to just test for the bit in the memory ops call backs > and do the swap there, but that would add overhead when it's not needed > (most guests don't need it) and there are two BARs to access the same > registers (one is in an IO BAR that aliases part of the MEM space BAR) and > these may need to have different endianness so I'd rather have the memory > layer handle it. > > Now the question is how can the endianness be changed from the memory ops > call back? Is it allowed to overwrite ops.endianness or replace ops with > another one that has DEVICE_BIG_ENDIAN? In MemoryRegion the ops field is > declared const and nothing seems to try to change it so I guess it might not > be changed. > > Then do I need to define two memory regions one with little and another with > big endian and unmap/map those when the bit is written? Can this be done > when a write to the bit happens with LE ops then is it possible from the > callback ro unmap the memory region being written and replace it with > another? Is there any other easy simple way that I'm missing?
I hope it'll just work as you said. It seems the same case to me comparing to other memory region updates within an MMIO callback, no matter whether the new MR only switched the endianness, or something else has changed. Thanks, -- Peter Xu
