Skip to contentSkip to conversation

Memory API: handling unassigned physical memory

Qemu-devel Blue Swirl 7 participants 33 messages May 1, 2012 – May 6, 2012 13 messages not in the archive

lore
Share & tools
lore

Blue Swirl

author
#7 lore raw
In reply to a message not in the archive
Quoted 9 lines · Mark Cave-Ayland

On 30/04/12 14:27, Peter Maydell wrote:

Hi Peter,

Quoted 4 lines
Quoted 2 lines

IMO the best fix is to unsysbus the device and qomify it instead.  This way we're 100% flexible in how we can attach it.

Quoted 5 lines
Quoted 2 lines

You don't need to wait for QOM to grow enough features to replace sysbus. If you don't like what sysbus_mmio_map() does, you

Oh - so does this mean that QOM is not feature-complete?

At least 'Pin' class to replace GPIOs and IRQs is not in HEAD (but Anthony already has a tree somewhere) and I can't remember what was the plan for buses.

Quoted 47 lines
Quoted 6 lines

can always use sysbus_mmio_get_region() to get the MemoryRegion* and then deal with it however you need to. This is the standard way to deal with "I have a sysbus device which I want to map into my custom container object".

I already have code to do this for the sun4m-only hardware modelled on sysbus_mmio_map() like this:

static void sbus_mmio_map(void *sbus, SysBusDevice *s, int n, target_phys_addr_t addr)
{
   MemoryRegion *sbus_mem, *mem;
   target_phys_addr_t sbus_base;
   SBusState *sbus_state = FROM_SYSBUS(SBusState, (SysBusDevice *)sbus);

   sbus_mem = sysbus_mmio_get_region((SysBusDevice *)sbus, 0); mem = sysbus_mmio_get_region(s, n);

   /* SBus addresses are physical addresses, so subtract start of region */ sbus_base = sbus_state->base; memory_region_add_subregion(sbus_mem, addr - sbus_base, mem); }

The key problem is that this doesn't worked with shared peripherals, such as the ESP device which is also used on various PPC Mac models as well as SPARC. That's because its init function looks like this:

void esp_init(target_phys_addr_t espaddr, int it_shift, ESPDMAMemoryReadWriteFunc dma_memory_read, ESPDMAMemoryReadWriteFunc dma_memory_write, void *dma_opaque, qemu_irq irq, qemu_irq *reset, qemu_irq *dma_enable)
{
   ...
   ...
   sysbus_mmio_map(s, 0, espaddr);
   ...
}

Quoted 6 lines

Therefore I can't change it to my (modified) sbus_mmio_map() function because it would break other non-SPARC platforms, and AIUI there is nothing in the memory API that allows me to move a subregion to a different MemoryRegion parent, even if I can get a reference to it with sysbus_mmio_get_region() after the sysbus_mmio_map() call - or have I misunderstood something?

Sysbus is used as a generic class for motherboard devices, there is an assumption that there is no higher level bus. What we need here is a full blown bus. The translations and mappigs between bus addresses and motherboard addresses should be done in a Sysbus to SBus bridge device, just like PCI host bridges do.

Quoted 6 lines

ATB,

Mark.

author
#15 lore raw
In reply to a message not in the archive
Quoted 22 lines · Mark Cave-Ayland
Quoted 16 lines · Peter Maydell
Quoted 7 lines

Therefore I can't change it to my (modified) sbus_mmio_map() function because it would break other non-SPARC platforms, and AIUI there is nothing
in the memory API that allows me to move a subregion to a different MemoryRegion parent, even if I can get a reference to it with sysbus_mmio_get_region() after the sysbus_mmio_map() call - or have I misunderstood something?

Init functions like esp_init should be purely convenience functions which create, set properties on, and map the sysbus/qdev device. If they make use of private knowledge about the internals of the device then this is wrong and should be fixed. For esp_init() it looks like the handling of dma_memory_read, dma_memory_write, dma_opaque, it_shift and dma_enabled are wrong.

Quoted 2 lines

If you fix that then you can just ignore the convenience function, and create, configure and map the device as appropriate for you.

Quoted 8 lines

Right I think I'm starting to understand this now - in which case it becomes a matter of just copying a handful of lines within sun4m which is more bearable.

In your view, would a suitable fix be to change dma_memory_read, dma_memory_write, dma_opaque, it_shift and dma_enabled to be qdev properties and modify esp_init() to return the qdev reference so they can be set by the caller?

There's an ongoing work to introduce IOMMUs by changing how DMA work and this could simplify the DMA part. There's no clean way to use function pointers in qdev.

For it_shift, a qdev or QOM property should be OK.

The signal dma_enabled should be eventually replaced by a Pin.

Quoted 6 lines

ATB,

Mark.

#20 lore raw
In reply to a message not in the archive
Quoted 15 lines · Peter Maydell
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Avi Kivity

IMO the best fix is to unsysbus the device and qomify it instead. This way we're 100% flexible in how we can attach it.

Quoted 8 lines
Quoted 6 lines

You don't need to wait for QOM to grow enough features to replace sysbus. If you don't like what sysbus_mmio_map() does, you can always use sysbus_mmio_get_region() to get the MemoryRegion* and then deal with it however you need to. This is the standard way to deal with "I have a sysbus device which I want to map into my custom container object".

I believe that API voids you warrantee.

Quoted 8 lines

I wrote it for essentially the purpose described above :-) If you're the owner of the sysbus device in question then it's entirely fine as you are the one deciding whether to use the traditional map function or not.

It's as good as we're going to get until QOM actually lets you export memory regions and pins, at which point we can just convert all the sysbus devices.

Sure. But expect breakage if sysbus changes, for example dropping use of get_system_memory().

Signature · 1 line
error compiling committee.c: too many arguments to function
#21 lore raw
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Peter Maydell

I wrote it for essentially the purpose described above :-) If you're the owner of the sysbus device in question then it's entirely fine as you are the one deciding whether to use the traditional map function or not.

Quoted 6 lines
Quoted 3 lines

It's as good as we're going to get until QOM actually lets you export memory regions and pins, at which point we can just convert all the sysbus devices.

Sure.  But expect breakage if sysbus changes, for example dropping use of get_system_memory().

That's OK, I'm happy to nak sysbus patches which break this use case :-)

-- PMM

#43 lore raw
In reply to a message not in the archive
Quoted 14 lines · Anthony Liguori
Quoted 13 lines · Avi Kivity
Quoted 11 lines · Peter Maydell
Quoted 3 lines · Avi Kivity

IMO the best fix is to unsysbus the device and qomify it instead. This
way we're 100% flexible in how we can attach it.

You don't need to wait for QOM to grow enough features to replace sysbus. If you don't like what sysbus_mmio_map() does, you can always use sysbus_mmio_get_region() to get the MemoryRegion* and then deal with it however you need to. This is the standard way to deal with "I have a sysbus device which I want to map into my custom container object".

Quoted 8 lines
Quoted 1 line

I believe that API voids you warrantee.

All that a "QOM" conversion would do is eliminate the use of sysbus and derive the object directly from DeviceState. Then, you would map the MemoryRegion exported by the device directly.

So sysbus_mmio_get_region() seems like the right API to use.

I think you're right. The real difference is that there is no longer an implied container region (which is just get_system_memory() in current sysbus).

Signature · 1 line
error compiling committee.c: too many arguments to function
#22 lore raw
In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Peter Maydell

I wrote it for essentially the purpose described above :-) If you're the owner of the sysbus device in question then it's entirely fine as you are the one deciding whether to use the traditional map function or not.

It's as good as we're going to get until QOM actually lets you export memory regions and pins, at which point we can just convert all the sysbus devices.

Quoted 5 lines
Quoted 2 lines

Sure. But expect breakage if sysbus changes, for example dropping use of get_system_memory().

That's OK, I'm happy to nak sysbus patches which break this use case :-)

sysbus should just die.

Signature · 1 line
error compiling committee.c: too many arguments to function
#23 lore raw
Quoted 1 line · Avi Kivity

sysbus should just die.

Totally agreed. It's not going to go quietly though...

-- PMM

#45 lore raw
In reply to a message not in the archive
Quoted 8 lines · Mark Cave-Ayland

On 30/04/12 14:23, Avi Kivity wrote:

Hi Avi,

Quoted 4 lines
Quoted 3 lines

My understanding based upon this is that it would be impossible to register a different parent MemoryRegion without duplicating the init function for all shared devices which seems undesirable :(

Quoted 8 lines
Quoted 3 lines

What are the requirements? You need a different catch-all mmio handler for each slot? Or would one catch-all mmio handler for all sysbus devices suffice?

A single catch-all for all sysbus devices would suffice, however I'm thinking it makes sense to have one MemoryRegion per slot so that the devices can register onto the bus using their "slot relative" address to allow for potentially moving hardware between slots.

Ok, so you have a hierarchy: bus -> slot -> devices in slot? That hierarchy is present in the hardware too, or that's how I interpret "slot relative addresses".

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

The only solution I can think of is to make sysbus_mmio_map() more intelligent so that instead of blindly adding the device to the "root" MemoryRegion, it traverses down the MemoryRegion hierarchy starting from the root to the furtherest leaf node it can find based upon the specified address and then adds the new subregion there. Hence if I add my SBus memory regions first before call the various peripheral init functions, everything should end up in the correct part of the memory tree.

Quoted 4 lines
Quoted 2 lines

This solution attempts to reconstruct the memory hierarchy from the address, instead of maintaining it in the device tree.

So I guess that is bad...

Well, it's a lot of work -> bad.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

I believe this should preserve compatibility for existing sysbus API users with just a single "root" MemoryRegion, however due to lack of any documentation related to sysbus I'm not sure if this would break other platforms or maybe even violate one of its key design features?

IMO the best fix is to unsysbus the device and qomify it instead. This way we're 100% flexible in how we can attach it.

That's interesting - I didn't realise that sysbus is a legacy interface with respect to QOM.

Maybe it's just wishful thinking on my part. But I always saw sysbus as a wrong interface - it corresponds to no real bus and doesn't allow hierarchy, unlike our pci or even isa implementations.

Quoted 4 lines

Is there any documentation related to this? Then again, converting all of the devices over to QOM and testing that it doesn't break all platforms/busses suddenly becomes a huge job...

You can just follow Peter's suggestion, although qomification would be preferable IMO.

Signature · 1 line
error compiling committee.c: too many arguments to function
#24 lore raw
In reply to Peter Maydell
Quoted 4 lines · Peter Maydell
Quoted 1 line · Avi Kivity

sysbus should just die.

Totally agreed. It's not going to go quietly though...

Not if you keep suggesting workarounds when I tell unsuspecting developers to qomify their devices.

Signature · 1 line
error compiling committee.c: too many arguments to function
#25 lore raw
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Peter Maydell
Quoted 1 line · Avi Kivity

sysbus should just die.

Totally agreed. It's not going to go quietly though...

Not if you keep suggesting workarounds when I tell unsuspecting developers to qomify their devices.

When QOM supports (1) exporting gpio signals and (2) exporting memory regions, then it will be providing the main things that sysbus provides. (Sysbus today is essentially "I need a device that exports some memory regions and some I/O pins".) At that point it will be sensible to say "convert your sysbus devices to QOM". Until QOM is actually able to provide the functionality, it's not a workable replacement.

-- PMM

#26 lore raw
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Peter Maydell
Quoted 1 line · Avi Kivity

sysbus should just die.

Totally agreed. It's not going to go quietly though...

Not if you keep suggesting workarounds when I tell unsuspecting developers to qomify their devices.

Quoted 7 lines

When QOM supports (1) exporting gpio signals and (2) exporting memory regions, then it will be providing the main things that sysbus provides. (Sysbus today is essentially "I need a device that exports some memory regions and some I/O pins".) At that point it will be sensible to say "convert your sysbus devices to QOM". Until QOM is actually able to provide the functionality, it's not a workable replacement.

Doesn't property<MemoryRegion> (or however it's phrased) provide the functionality for memory?

But I agree.

Signature · 1 line
error compiling committee.c: too many arguments to function
#27 lore raw
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Peter Maydell
Quoted 2 lines · Avi Kivity
Quoted 1 line · Peter Maydell

On 1 May 2012 13:42, Avi Kivity<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

sysbus should just die.

Totally agreed. It's not going to go quietly though...

Not if you keep suggesting workarounds when I tell unsuspecting developers to qomify their devices.

When QOM supports (1) exporting gpio signals and

This is trivial. It'll come in as soon as 1.2 opens up. If folks want to start working on a branch with it:

https://github.com/aliguori/qemu/tree/qom-pin.4

Quoted 2 lines
Quoted 2 lines

(2) exporting memory regions, then it will be providing the main things that sysbus provides.

This is a little tricky. Here's the problems I've encountered so far:

a) A lot of devices need the equivalent of it_shift. it_shift affects how addresses are decoded and the size of the memory region. it_shift usually needs to be a device property.

Since we need to know the size of the memory region to initialize it, we need to know the value of it_shift before we can initialize it which means we have to delay the initialization of the mmemory region until realize.

I think a nice fix would be to make it_shift as memory region mutator and allow it to be set after initialization.

b) There's some duplication in MemoryRegions with respect to QOM. Memory regions want to have a name but with QOM they'll be addressable via a path. I go back and forth about how aggressively we want to refactor MemoryRegions.

If someone wants to spend some time converting MemoryRegion to QOM, that would certainly be helpful. So far, I've been avoiding it but we'll eventually need to do it.

Regards,

Anthony Liguori

#8 lore raw
In reply to Blue Swirl
Quoted 15 lines · Blue Swirl
Quoted 13 lines · Mark Cave-Ayland

On 30/04/12 14:27, Peter Maydell wrote:

Hi Peter,

Quoted 6 lines
Quoted 2 lines

IMO the best fix is to unsysbus the device and qomify it instead. This way we're 100% flexible in how we can attach it.

You don't need to wait for QOM to grow enough features to replace sysbus. If you don't like what sysbus_mmio_map() does, you

Quoted 5 lines
Quoted 1 line

Oh - so does this mean that QOM is not feature-complete?

At least 'Pin' class to replace GPIOs and IRQs is not in HEAD (but Anthony already has a tree somewhere) and I can't remember what was the plan for buses.

I'm planning on pushing bus support in before I freeze 1.1.

Regards,

Anthony Liguori

#28 lore raw
In reply to Anthony Liguori
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Peter Maydell
Quoted 1 line

When QOM supports (1) exporting gpio signals and

This is trivial.  It'll come in as soon as 1.2 opens up.

You need to get it through code review first...

(just as a random example, this commit:
https://github.com/aliguori/qemu/commit/46483049813fca2c23fb7cd04eeab89905500c4c
is going down the wrong path because it's incorrectly introducing knowledge of device internals to the utility i8259_init() function.)

-- PMM

#29 lore raw
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Peter Maydell
Quoted 1 line

When QOM supports (1) exporting gpio signals and

This is trivial. It'll come in as soon as 1.2 opens up.

You need to get it through code review first...

Obviously.

Quoted 6 lines

(just as a random example, this commit:
https://github.com/aliguori/qemu/commit/46483049813fca2c23fb7cd04eeab89905500c4c
is going down the wrong path because it's incorrectly introducing knowledge of device internals to the utility i8259_init() function.)

Eh?

Do you mean:

- qdev_connect_gpio_out(&dev->qdev, 0, irq_set[2]);
+ pin_connect_qemu_irq(&s->int_out[0], irq_set[2]);

There are three ways to do this:

1) pin_connect_qemu_irq(i8259_get_int_out(s), irq_set[2]);

2) pin_connect_qemu_irq(&s->int_out[0], irq_set[2]);

3) pin_connect_qemu_irq(PIN(object_get_child(s, "int_out[0]")), irq_set[2]);

Having converted a lot of devices by hand, I prefer (2). I'd like to move to a model of:

typedef struct PICDevice

{
    DeviceState parent;

    Pin int_out[0];
    MemoryRegion io;

    /*< private >*/
    PICState *priv;
} PICDevice;

This let's us use (2), while still embedding devices and keeping the gory state details private to the implementation.

Regards,

Anthony Liguori

Quoted 2 lines

-- PMM

#38 lore raw
In reply to Anthony Liguori
Quoted 28 lines · Anthony Liguori
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Peter Maydell
Quoted 2 lines · Avi Kivity
Quoted 1 line · Peter Maydell

On 1 May 2012 13:42, Avi Kivity<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

sysbus should just die.

Totally agreed. It's not going to go quietly though...

Not if you keep suggesting workarounds when I tell unsuspecting developers to qomify their devices.

When QOM supports (1) exporting gpio signals and

This is trivial. It'll come in as soon as 1.2 opens up. If folks want to start working on a branch with it:

https://github.com/aliguori/qemu/tree/qom-pin.4

Quoted 2 lines
Quoted 2 lines

(2) exporting memory regions, then it will be providing the main things that sysbus provides.

This is a little tricky. Here's the problems I've encountered so far:

a) A lot of devices need the equivalent of it_shift. it_shift affects how addresses are decoded and the size of the memory region. it_shift usually needs to be a device property.

Quoted 7 lines

Since we need to know the size of the memory region to initialize it, we need to know the value of it_shift before we can initialize it which means we have to delay the initialization of the mmemory region until realize.

I think a nice fix would be to make it_shift as memory region mutator and allow it to be set after initialization.

Indeed I wanted to make it_shift as part of the memory core. But a mutator? It doesn't change in real hardware, so this looks artificial. So far all mutators really change at runtime.

What is the problem with delaying region initialization until realize?

Quoted 5 lines

b) There's some duplication in MemoryRegions with respect to QOM. Memory regions want to have a name but with QOM they'll be addressable via a path. I go back and forth about how aggressively we want to refactor MemoryRegions.

These days region names are purely for debugging. The ABI bit was moved to a separate function.

Signature · 1 line
error compiling committee.c: too many arguments to function
#39 lore raw
Quoted 34 lines · Avi Kivity
Quoted 33 lines · Anthony Liguori
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Peter Maydell
Quoted 2 lines · Avi Kivity
Quoted 1 line · Peter Maydell

On 1 May 2012 13:42, Avi Kivity<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

sysbus should just die.

Totally agreed. It's not going to go quietly though...

Not if you keep suggesting workarounds when I tell unsuspecting developers to qomify their devices.

When QOM supports (1) exporting gpio signals and

This is trivial. It'll come in as soon as 1.2 opens up. If folks want to start working on a branch with it:

https://github.com/aliguori/qemu/tree/qom-pin.4

Quoted 2 lines
Quoted 2 lines

(2) exporting memory regions, then it will be providing the main things that sysbus provides.

This is a little tricky. Here's the problems I've encountered so far:

a) A lot of devices need the equivalent of it_shift. it_shift affects how addresses are decoded and the size of the memory region. it_shift usually needs to be a device property.

Since we need to know the size of the memory region to initialize it, we need to know the value of it_shift before we can initialize it which means we have to delay the initialization of the mmemory region until realize.

Quoted 6 lines
Quoted 2 lines

I think a nice fix would be to make it_shift as memory region mutator and allow it to be set after initialization.

Indeed I wanted to make it_shift as part of the memory core. But a mutator? It doesn't change in real hardware, so this looks artificial. So far all mutators really change at runtime.

QOM has a concept of initialization and realize. You can change properties after initialization but not before realize.

So as long as it_shift can be set after initialization but before realize (which I think is roughly memory_region_add_subregion) it doesn't need to be a mutator.

Quoted 1 line

What is the problem with delaying region initialization until realize?

We need to initialize the MemoryRegion in order to expose it as a property. We want to do that during initialize. Here's an example:

qom-create isa-i8259 foo
qom-set /peripheral/foo/io it_shift 1
qom-set /peripheral/foo/realize true

For this to work, it_shift needs to be a QOM property of the "io" MemoryRegion.
The MemoryRegion needs to be created in instance_init.

Quoted 7 lines
Quoted 4 lines

b) There's some duplication in MemoryRegions with respect to QOM. Memory regions want to have a name but with QOM they'll be addressable via a path. I go back and forth about how aggressively we want to refactor MemoryRegions.

These days region names are purely for debugging. The ABI bit was moved to a separate function.

Fair enough.

BTW, in the branch I've posted, I've got a number of memory API conversions or removal of legacy interfaces.

Regards,

Anthony Liguori

#30 lore raw
In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori

Do you mean:

-    qdev_connect_gpio_out(&dev->qdev, 0, irq_set[2]);
+    pin_connect_qemu_irq(&s->int_out[0], irq_set[2]);

There are three ways to do this:

1) pin_connect_qemu_irq(i8259_get_int_out(s), irq_set[2]);

No good unless you're autogenerating all those accessor functions.

Quoted 1 line

2) pin_connect_qemu_irq(&s->int_out[0], irq_set[2]);

Exposes the whole of the struct (including all the private memmbers) to anything that wants to use it. As you say later on in the email, this requires splitting everything up into two structs, one for "publicly accessible" and one for "private implementation"...which your series doesn't seem to do at the moment.

Quoted 1 line

3) pin_connect_qemu_irq(PIN(object_get_child(s, "int_out[0]")), irq_set[2]);

This is a bit verbose. Something more like
pin_connect(s, "int_out[0]", self, "int_set[2]");
would be a bit less longwinded. Or even
connect(TYPE_PIN, s, "int_out[0]", self, "int_set[2]");

(No, this doesn't do compile time type checking. I don't think that's a problem particularly, or at least not enough of one to justify not doing it this way. The object model we have is dynamic and does things at runtime...)

-- PMM

#40 lore raw
In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 6 lines
Quoted 2 lines

I think a nice fix would be to make it_shift as memory region mutator and allow it to be set after initialization.

Indeed I wanted to make it_shift as part of the memory core. But a mutator? It doesn't change in real hardware, so this looks artificial. So far all mutators really change at runtime.

Quoted 6 lines

QOM has a concept of initialization and realize. You can change properties after initialization but not before realize.

So as long as it_shift can be set after initialization but before realize (which I think is roughly memory_region_add_subregion) it doesn't need to be a mutator.

Ok, good.

Quoted 6 lines
Quoted 2 lines

What is the problem with delaying region initialization until realize?

We need to initialize the MemoryRegion in order to expose it as a property. We want to do that during initialize. Here's an example:

Quoted 6 lines

qom-create isa-i8259 foo
qom-set /peripheral/foo/io it_shift 1
qom-set /peripheral/foo/realize true

For this to work, it_shift needs to be a QOM property of the "io" MemoryRegion. The MemoryRegion needs to be created in instance_init.

So it looks like we need two phase initialization for memory regions as well?

Not so pretty.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

b) There's some duplication in MemoryRegions with respect to QOM. Memory regions want to have a name but with QOM they'll be addressable via a path. I go back and forth about how aggressively we want to refactor MemoryRegions.

Quoted 7 lines
Quoted 2 lines

These days region names are purely for debugging. The ABI bit was moved to a separate function.

Fair enough.

BTW, in the branch I've posted, I've got a number of memory API conversions or removal of legacy interfaces.

Nice. But you use get_system_io(), which is bad.

Signature · 1 line
error compiling committee.c: too many arguments to function
#31 lore raw
In reply to Peter Maydell
Quoted 21 lines · Peter Maydell
Quoted 8 lines · Anthony Liguori

Do you mean:

(quoted diff) +1 -1
-    qdev_connect_gpio_out(&dev->qdev, 0, irq_set[2]);
+    pin_connect_qemu_irq(&s->int_out[0], irq_set[2]);

There are three ways to do this:

1) pin_connect_qemu_irq(i8259_get_int_out(s), irq_set[2]);

No good unless you're autogenerating all those accessor functions.

Quoted 1 line

2) pin_connect_qemu_irq(&s->int_out[0], irq_set[2]);

Exposes the whole of the struct (including all the private memmbers) to anything that wants to use it. As you say later on in the email, this requires splitting everything up into two structs, one for "publicly accessible" and one for "private implementation"...which your series doesn't seem to do at the moment.

Quoted 4 lines
Quoted 1 line

3) pin_connect_qemu_irq(PIN(object_get_child(s, "int_out[0]")), irq_set[2]);

This is a bit verbose. Something more like
pin_connect(s, "int_out[0]", self, "int_set[2]");

This is incorrect, it would have to be:

Error *err = NULL;

if (pin_connect(s, "in_out[0]", self, "int_set[2]", &err)) {
error_propagate(errp, err);
return;
}

Quoted 2 lines

would be a bit less longwinded. Or even
connect(TYPE_PIN, s, "int_out[0]", self, "int_set[2]");

Not checking for failure is not an option.

Quoted 4 lines

(No, this doesn't do compile time type checking. I don't think that's a problem particularly, or at least not enough of one to justify not doing it this way. The object model we have is dynamic and does things at runtime...)

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init(). These types of functions should go away in favor of proper modeling of SoCs/SuperIO chips.

Regards,

Anthony Liguori

Quoted 2 lines

-- PMM

#41 lore raw
In reply to Avi Kivity
Quoted 28 lines · Avi Kivity
Quoted 8 lines · Anthony Liguori
Quoted 6 lines
Quoted 2 lines

I think a nice fix would be to make it_shift as memory region mutator and allow it to be set after initialization.

Indeed I wanted to make it_shift as part of the memory core. But a mutator? It doesn't change in real hardware, so this looks artificial. So far all mutators really change at runtime.

Quoted 6 lines

QOM has a concept of initialization and realize. You can change properties after initialization but not before realize.

So as long as it_shift can be set after initialization but before realize (which I think is roughly memory_region_add_subregion) it doesn't need to be a mutator.

Ok, good.

Quoted 10 lines
Quoted 2 lines

What is the problem with delaying region initialization until realize?

We need to initialize the MemoryRegion in order to expose it as a property. We want to do that during initialize. Here's an example:

qom-create isa-i8259 foo
qom-set /peripheral/foo/io it_shift 1
qom-set /peripheral/foo/realize true

Quoted 5 lines
Quoted 2 lines

For this to work, it_shift needs to be a QOM property of the "io" MemoryRegion. The MemoryRegion needs to be created in instance_init.

So it looks like we need two phase initialization for memory regions as well?

Yes, exactly. Converting MemoryRegion to QOM will give it a two phase initialization FWIW.

Quoted 1 line

Not so pretty.

It's unavoidable because we're dealing with a graph. The connections between objects may form loops which effectively means that we have dependency loops. That means we need to be able to create all objects first and then establish the links between them. This is why we need two stage initialization.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

b) There's some duplication in MemoryRegions with respect to QOM. Memory regions want to have a name but with QOM they'll be addressable via a path. I go back and forth about how aggressively we want to refactor MemoryRegions.

These days region names are purely for debugging. The ABI bit was moved to a separate function.

Quoted 6 lines
Quoted 4 lines

Fair enough.

BTW, in the branch I've posted, I've got a number of memory API conversions or removal of legacy interfaces.

Nice. But you use get_system_io(), which is bad.

Only in the device setup code. That will all eventually get moved into a SuperIO chip. The PC code needs massive amounts of refactoring.

Regards,

Anthony Liguori

Quoted 1 line
#32 lore raw
In reply to Anthony Liguori
Quoted 12 lines · Anthony Liguori
Quoted 2 lines · Peter Maydell

This is a bit verbose. Something more like pin_connect(s, "int_out[0]", self, "int_set[2]");

This is incorrect, it would have to be:

Error *err = NULL;

if (pin_connect(s, "in_out[0]", self, "int_set[2]", &err)) { error_propagate(errp, err);
  return;

Quoted 7 lines

}

Quoted 2 lines

would be a bit less longwinded. Or even connect(TYPE_PIN, s, "int_out[0]", self, "int_set[2]");

Not checking for failure is not an option.

The assumption is that failure to connect is a fatal error, and we can happily just assert()/hw_error()/etc. (Obviously we would provide APIs for the occasional use case that really did want to do "connect if possible and do something else in case of failure", but that's definitely not the common case.)

Quoted 8 lines
Quoted 4 lines

(No, this doesn't do compile time type checking. I don't think that's a problem particularly, or at least not enough of one to justify not doing it this way. The object model we have is dynamic and does things at runtime...)

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init().

Functions like i8259_init() exist precisely because QOM/qdev don't provide brevity and people trying to use these devices do in fact value brevity. That's why I want the standard native "connect this thing to this other thing" function to be short and simple.

-- PMM

#33 lore raw
Quoted 15 lines · Peter Maydell
Quoted 14 lines · Anthony Liguori
Quoted 2 lines · Peter Maydell

This is a bit verbose. Something more like
pin_connect(s, "int_out[0]", self, "int_set[2]");

This is incorrect, it would have to be:

Error *err = NULL;

if (pin_connect(s, "in_out[0]", self, "int_set[2]",&err)) {
   error_propagate(errp, err);
   return;

}

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

would be a bit less longwinded. Or even
connect(TYPE_PIN, s, "int_out[0]", self, "int_set[2]");

Not checking for failure is not an option.

The assumption is that failure to connect is a fatal error, and we can happily just assert()/hw_error()/etc.

So that means that we have a bug from someone miss-typing, instead of your hotplug attempt failing with an error, your entire guest is destroyed. That doesn't sound very nice to me.

Device initialization should never exit() (unless you really hit a fatal error like OOM).

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

(No, this doesn't do compile time type checking. I don't think that's a problem particularly, or at least not enough of one to justify not doing it this way. The object model we have is dynamic and does things at runtime...)

Quoted 7 lines
Quoted 3 lines

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init().

Functions like i8259_init() exist precisely because QOM/qdev don't provide brevity and people trying to use these devices do in fact value brevity.

No, they exist because we aren't modeling correctly.

i8259_init() is doing a few different things at once. Once you split things between init and realize, you no longer have long chunks of redundant code.

Quoted 3 lines

That's why
I want the standard native "connect this thing to this other thing" function to be short and simple.

With my previous proposal, it's just:

s->irq_in = &b->int_out[0];

This is why I like exposing public members in structures. It's brief and safe.

Regards,

Anthony Liguori

Quoted 2 lines

-- PMM

#34 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 2 lines · Peter Maydell

The assumption is that failure to connect is a fatal error, and we can happily just assert()/hw_error()/etc.

So that means that we have a bug from someone miss-typing, instead of your hotplug attempt failing with an error, your entire guest is destroyed.  That doesn't sound very nice to me.

If you're trying to hotplug a buggily implemented device then all bets are off, really.

Quoted 15 lines

Device initialization should never exit() (unless you really hit a fatal error like OOM).

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

(No, this doesn't do compile time type checking. I don't think that's a problem particularly, or at least not enough of one to justify not doing it this way. The object model we have is dynamic and does things at runtime...)

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init().

Quoted 6 lines
Quoted 3 lines

Functions like i8259_init() exist precisely because QOM/qdev don't provide brevity and people trying to use these devices do in fact value brevity.

No, they exist because we aren't modeling correctly.

Most of them are simply convenience functions that just do "create, configure, wire up, init". (The ones that do more than that need fixing anyway.)

Quoted 3 lines

i8259_init() is doing a few different things at once. Once you split things between init and realize, you no longer have long chunks of redundant code.

...you have redundant code scattered in multiple places instead?

Quoted 11 lines
Quoted 3 lines

That's why
I want the standard native "connect this thing to this other thing" function to be short and simple.

With my previous proposal, it's just:

s->irq_in = &b->int_out[0];

This is why I like exposing public members in structures.  It's brief and safe.

Obvious question: why isn't property setting done this way, then? Surely it's equally brief and safe to say
cpu->level = def_level;
rather than
object_property_set_int(OBJECT(cpu), def->level, "level", &error);

I don't particularly object to this sort of "public struct vs private struct" object model, it's just not what you've actually implemented.

-- PMM

#35 lore raw
Quoted 7 lines · Peter Maydell
Quoted 5 lines · Anthony Liguori
Quoted 2 lines · Peter Maydell

The assumption is that failure to connect is a fatal error, and we can happily just assert()/hw_error()/etc.

So that means that we have a bug from someone miss-typing, instead of

your

Quoted 1 line
Quoted 1 line

hotplug attempt failing with an error, your entire guest is destroyed.

That

Quoted 4 lines
Quoted 1 line

doesn't sound very nice to me.

If you're trying to hotplug a buggily implemented device then all bets are off, really.

Its never okay to kill a guest. We should fail gracefully when possible or simply avoid failing in the first place.

Quoted 22 lines
Quoted 15 lines

Device initialization should never exit() (unless you really hit a fatal error like OOM).

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

(No, this doesn't do compile time type checking. I don't think that's a problem particularly, or at least not enough of one to justify not doing it this way. The object model we have is dynamic and does things at runtime...)

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init().

Quoted 6 lines
Quoted 3 lines

Functions like i8259_init() exist precisely because QOM/qdev don't provide brevity and people trying to use these devices do in fact value brevity.

No, they exist because we aren't modeling correctly.

Quoted 8 lines

Most of them are simply convenience functions that just do "create, configure, wire up, init". (The ones that do more than that need fixing anyway.

Quoted 3 lines

i8259_init() is doing a few different things at once. Once you split things between init and realize, you no longer have long chunks of redundant code.

...you have redundant code scattered in multiple places instead?

Redundant is the wrong word. It seems like the code ought to be reduced to a single function call but it really cannot.

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

That's why
I want the standard native "connect this thing to this other thing" function to be short and simple.

With my previous proposal, it's just:

s->irq_in = &b->int_out[0];

This is why I like exposing public members in structures. It's brief

and

Quoted 7 lines
Quoted 1 line

safe.

Obvious question: why isn't property setting done this way, then? Surely it's equally brief and safe to say
cpu->level = def_level;
rather than
object_property_set_int(OBJECT(cpu), def->level, "level", &error);

A primary design consideration for QOM was to *not* require using the generic property interface to set properties. That doesnt mean that you can/should access all properties this way. It depends on the specific property.

Quoted 3 lines

I don't particularly object to this sort of "public struct vs private struct" object model, it's just not what you've actually implemented.

One step at a time.

Regards,

Anthony Liguori

Quoted 2 lines

-- PMM

#9 lore raw
In reply to Blue Swirl
Quoted 7 lines · Blue Swirl
Quoted 6 lines

Therefore I can't change it to my (modified) sbus_mmio_map() function because it would break other non-SPARC platforms, and AIUI there is nothing in the memory API that allows me to move a subregion to a different MemoryRegion parent, even if I can get a reference to it with sysbus_mmio_get_region() after the sysbus_mmio_map() call - or have I misunderstood something?

Quoted 5 lines

Sysbus is used as a generic class for motherboard devices, there is an assumption that there is no higher level bus. What we need here is a full blown bus. The translations and mappigs between bus addresses and motherboard addresses should be done in a Sysbus to SBus bridge device, just like PCI host bridges do.

Since SBus is mapped directly to physical addresses, is this mapping not just 1:1? Or does it make sense to re-work all the offsets of the various peripherals to be from the base address of the first slot?

ATB,

Mark.

#16 lore raw
In reply to Blue Swirl
Quoted 8 lines · Blue Swirl
Quoted 4 lines

In your view, would a suitable fix be to change dma_memory_read, dma_memory_write, dma_opaque, it_shift and dma_enabled to be qdev properties and modify esp_init() to return the qdev reference so they can be set by the caller?

There's an ongoing work to introduce IOMMUs by changing how DMA work and this could simplify the DMA part. There's no clean way to use function pointers in qdev.

In my current working tree, I have actually managed to get this working with a customised qdev type macro and the standard qdev pointer type - so it may not be particularly great, but it works.

Quoted 3 lines

For it_shift, a qdev or QOM property should be OK.

The signal dma_enabled should be eventually replaced by a Pin.

And this is a sysbus concept, yes?

ATB,

Mark.

#36 lore raw
In reply to Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 3 lines

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init().

Functions like i8259_init() exist precisely because QOM/qdev don't provide brevity and people trying to use these devices do in fact value brevity. That's why I want the standard native "connect this thing to this other thing" function to be short and simple.

My understanding was that the *_init() functions were legacy and shouldn't be used any more - at least I've started removing them and replacing them with the slighty more long-winded QOM versions in my working tree.

Or should I just leave them as they are copy the bits I need to a separate initialisation function?

ATB,

Mark.

#37 lore raw
Quoted 14 lines · Mark Cave-Ayland
Quoted 10 lines · Peter Maydell
Quoted 3 lines

Correctness is more important to me than brevity.

And really, we should focus on killing things like i8259_init().

Functions like i8259_init() exist precisely because QOM/qdev don't provide brevity and people trying to use these devices do in fact value brevity. That's why I want the standard native "connect this thing to this other thing" function to be short and simple.

Quoted 3 lines

My understanding was that the *_init() functions were legacy and shouldn't be used any more - at least I've started removing them and replacing them with the slighty more long-winded QOM versions in my working tree.

Yes, that is my opinion and is why I'm arguing with Anthony here...

-- PMM

#17 lore raw
In reply to Mark Cave-Ayland

Am 01.05.2012 20:50, schrieb Mark Cave-Ayland:

Quoted 4 lines · Blue Swirl
Quoted 1 line

The signal dma_enabled should be eventually replaced by a Pin.

And this is a sysbus concept, yes?

No, it'll be a general DeviceState concept.
SysBus is supposed to die out gradually.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#10 lore raw
In reply to Mark Cave-Ayland
Quoted 16 lines · Mark Cave-Ayland
Quoted 8 lines · Blue Swirl
Quoted 7 lines

Therefore I can't change it to my (modified) sbus_mmio_map() function because it would break other non-SPARC platforms, and AIUI there is nothing
in the memory API that allows me to move a subregion to a different MemoryRegion parent, even if I can get a reference to it with sysbus_mmio_get_region() after the sysbus_mmio_map() call - or have I misunderstood something?

Quoted 5 lines

Sysbus is used as a generic class for motherboard devices, there is an assumption that there is no higher level bus. What we need here is a full blown bus. The translations and mappigs between bus addresses and motherboard addresses should be done in a Sysbus to SBus bridge device, just like PCI host bridges do.

Quoted 3 lines

Since SBus is mapped directly to physical addresses, is this mapping not just 1:1? Or does it make sense to re-work all the offsets of the various peripherals to be from the base address of the first slot?

It would be nice to have the device offsets be relative to the slot. User-pluggable sbus devices should be possible.

I've just pushed an update of a dbri sbus device model to github (
https://github.com/breuerr/qemu/commits/dbri-pre2 ). This device was built-in to at least the SS-20, but also available as an sbus add-in card (SunLink ISDN). There's an fcode rom so it can be probed by OBP, and if we could get something like "-device SUNW,,DBRIe,slot=1" to work, then a user could add it to most of the sun4m machine models.

Bob

author
#12 lore raw
In reply to Mark Cave-Ayland
Quoted 18 lines · Mark Cave-Ayland
Quoted 9 lines · Blue Swirl
Quoted 7 lines

Therefore I can't change it to my (modified) sbus_mmio_map() function because it would break other non-SPARC platforms, and AIUI there is nothing
in the memory API that allows me to move a subregion to a different MemoryRegion parent, even if I can get a reference to it with sysbus_mmio_get_region() after the sysbus_mmio_map() call - or have I misunderstood something?

Quoted 5 lines

Sysbus is used as a generic class for motherboard devices, there is an assumption that there is no higher level bus. What we need here is a full blown bus. The translations and mappigs between bus addresses and motherboard addresses should be done in a Sysbus to SBus bridge device, just like PCI host bridges do.

Quoted 3 lines

Since SBus is mapped directly to physical addresses, is this mapping not just 1:1? Or does it make sense to re-work all the offsets of the various peripherals to be from the base address of the first slot?

The mapping is not direct, from device point of view there's IOMMU in between and without help from IOMMU (or using the direct mode) the device can't access the full 36 bit address space. The offset should be from the start of the current slot, not first slot.

Quoted 5 lines

ATB,

Mark.

author
#11 lore raw
In reply to Bob Breuer
Quoted 17 lines · Bob Breuer
Quoted 16 lines · Mark Cave-Ayland
Quoted 13 lines · Blue Swirl
Quoted 7 lines

Therefore I can't change it to my (modified) sbus_mmio_map() function because it would break other non-SPARC platforms, and AIUI there is nothing
in the memory API that allows me to move a subregion to a different MemoryRegion parent, even if I can get a reference to it with sysbus_mmio_get_region() after the sysbus_mmio_map() call - or have I misunderstood something?

Sysbus is used as a generic class for motherboard devices, there is an assumption that there is no higher level bus. What we need here is a full blown bus. The translations and mappigs between bus addresses and motherboard addresses should be done in a Sysbus to SBus bridge device, just like PCI host bridges do.

Quoted 6 lines
Quoted 3 lines

Since SBus is mapped directly to physical addresses, is this mapping not just 1:1? Or does it make sense to re-work all the offsets of the various peripherals to be from the base address of the first slot?

It would be nice to have the device offsets be relative to the slot. User-pluggable sbus devices should be possible.

Yes, currently all devices are fixed but for example display adapter should be pluggable and only on-board devices should be fixed.

Quoted 6 lines

I've just pushed an update of a dbri sbus device model to github (
https://github.com/breuerr/qemu/commits/dbri-pre2 ).  This device was built-in to at least the SS-20, but also available as an sbus add-in card (SunLink ISDN).  There's an fcode rom so it can be probed by OBP, and if we could get something like "-device SUNW,,DBRIe,slot=1" to work, then a user could add it to most of the sun4m machine models.

Nice work.

Quoted 2 lines

Bob