Skip to contentSkip to conversation

Add support for Xen ARM guest on FreeBSD

RFC Warner Losh 5 participants 18 messages Jan 15, 2014 – Jan 19, 2014 11 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 14 lines · Julien Grall

This new support brings 2 open questions (for both Xen and FreeBSD community). When a new guest is created, the toolstack will generated a device tree which will contains:
- The amount of memory
- The description of the platform (gic, timer, hypervisor node)
- PSCI node for SMP bringup

Until now, Xen on ARM supported only Linux-based OS. When the support of device tree was added in Xen for guest, we chose to use Linux device tree bindings (gic, timer,...). It seems that FreeBSD choose a different way to implement device tree:
- strictly respect ePAR (for interrupt-parent property)
- gic bindings different (only 1 interrupt cell)

Quoted 4 lines

I would like to come with a common device tree specification (bindings, ...) across every operating system. I know the Linux community is working on having a device tree bindings out of the kernel tree. Does FreeBSD community plan to work with Linux community for this purpose?

We generally try to follow the common definitions for the FDT stuff. There are a few cases where we either lack the feature set of Linux, or where the Linux folks are moving quickly and changing the underlying definitions where we wait for the standards to mature before we implement. In some cases, where maturity hasn't happened, or where the bindings are overly Linux centric (which in theory they aren't supposed to be, but sometimes wind up that way). where we've not implemented things.

Quoted 3 lines

As specified early, the device tree can vary accross Xen version and user input (eg the memory). I have noticed few places (mainly the timer) where the IRQs number are harcoded.

These cases should be viewed as bugs in FreeBSD, I believe. One of the goals that has wide support, at leas tin theory, is that we can boot with an unaltered Linux FDT. This goal is some time in the future.

Quoted 4 lines

In the long-term, it would be nice to see FreeBSD booting out-of-box (eg the device tree is directly provided by the board firmware). I plan to add support for Device Tree loading via Linux Boot ABI, it the way that Xen use to boot a new guest.

That would be most welcome.

Quoted 7 lines

The second question is related to memory attribute for page table. The early page table setup by FreeBSD are using Write-Through memory attribute which result to a likely random (not every time the same place) crash before the real page table are initialized.
Replacing Write-Through by Write-Back made FreeBSD boot correctly. Even today, I have no idea if it's a requirement from Xen or a bug (either in Xen or FreeBSD).

There were some problems with pages being setup improperly for the mutexes to operate properly. Have you confirmed this on a recent version of FreeBSD?

Quoted 11 lines

The code is taking its first faltering steps, therefore the TODO is quite big:
- Try the code on x86 architecture. I did lots of rework for the event channels code and didn't even try to compile
- Clean up event channel code
- Clean up xen control code
- Add support for Device Tree loading via Linux Boot ABI
- Fixing crashing on userspace. Could be related to the patch series "arm SMP on Cortex-A15"
- Add guest SMP support
- DOM0 support?

Quoted 1 line

Any help, comments, questions are welcomed.

I think this is great! We'd love to work with you to make this happen.

Warner

Quoted 3 lines

Sincerely yours,

============= Instruction to test FreeBSD on Xen on ARM ===========

[trimmed]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 16 lines · Warner Losh
Quoted 14 lines · Julien Grall

This new support brings 2 open questions (for both Xen and FreeBSD community). When a new guest is created, the toolstack will generated a device tree which will contains:
- The amount of memory
- The description of the platform (gic, timer, hypervisor node)
- PSCI node for SMP bringup

Until now, Xen on ARM supported only Linux-based OS. When the support of device tree was added in Xen for guest, we chose to use Linux device tree bindings (gic, timer,...). It seems that FreeBSD choose a different way to implement device tree:
- strictly respect ePAR (for interrupt-parent property)
- gic bindings different (only 1 interrupt cell)

Quoted 8 lines
Quoted 4 lines

I would like to come with a common device tree specification (bindings, ...) across every operating system. I know the Linux community is working on having a device tree bindings out of the kernel tree. Does FreeBSD community plan to work with Linux community for this purpose?

We generally try to follow the common definitions for the FDT stuff. There are a few cases where we either lack the feature set of Linux, or where the Linux folks are moving quickly and changing the underlying

definitions

Quoted 1 line

where we wait for the standards to mature before we implement. In some

cases, where

Quoted 1 line

maturity hasn't happened, or where the bindings are overly Linux

centric (which in

Quoted 1 line

theory they aren't supposed to be, but sometimes wind up that way).

where we've not

Quoted 1 line

implemented things.

As I understand main bindings (gic, timer) are set in stone and won't change. Ian Campbell has a repository with all the ARM bindings here:
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;
a=tree;f=Bindings/arm

To compare the difference between the DT provided by Xen, and the one correctly parsed by FreeBSD
- Xen: http://xenbits.xen.org/people/julieng/xenvm-4.2.dts
- FreeBSD: http://xenbits.xen.org/people/julieng/xenvm-bsd.dts

Quoted 1 line

From Xen side:

- Every device should move under a simple-bus. I think it's harmless
for Linux side.
- How about hypervisor node? IHMO this node should also live under the
simple-bus.

Quoted 1 line

From FreeBSD side:

- GIC and Timer bindings needs to be handled correctly (see below the
problem for the GIC)
- Less stricter about interrupt-parent property. Eg, look at the
grant-parent if there is no property interrupt-parent
- If the hypervisor doesn't live under simple-bus, the interrupt/memory
retrieving should be moved from simple-bus to nexus?

Before the revision r260282 (I have added Nathan on cc), I was able to use the Linux GIC bindings (see
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;a=blob;f=Bindings/arm/gic.txt)
without any issue.

It seems the fdt bus, now consider the number of interrupt cells is always 1.

Quoted 6 lines
Quoted 3 lines

As specified early, the device tree can vary accross Xen version and user input (eg the memory). I have noticed few places (mainly the timer) where the IRQs number are harcoded.

These cases should be viewed as bugs in FreeBSD, I believe. One of the goals that has wide support, at leas tin theory, is that we can boot with an

unaltered

Quoted 1 line

Linux FDT. This goal is some time in the future.

The timer interrupt used by FreeBSD doesn't match the one used by Xen (secure vs non-secure interrupt). This should be easily resolved by retrieving the interrupt from the device tree.

Is there a particular reason to use the secure interrupt for the timer?

Quoted 11 lines
Quoted 8 lines

The second question is related to memory attribute for page table. The early page table setup by FreeBSD are using Write-Through memory attribute which result to a likely random (not every time the same place) crash before the real page table are initialized.
Replacing Write-Through by Write-Back made FreeBSD boot correctly. Even today, I have no idea if it's a requirement from Xen or a bug (either in Xen or FreeBSD).

There were some problems with pages being setup improperly for the mutexes to operate properly. Have you confirmed this on a recent version of

FreeBSD?

I have checkout the freeBSD branch last week.

I'm not sure to understand the relation with mutexes. The symptoms I have is mostly data/prefetch abort receive to FreeBSD. Could it be related?

Quoted 22 lines
Quoted 11 lines

The code is taking its first faltering steps, therefore the TODO is quite big:
- Try the code on x86 architecture. I did lots of rework for the event channels code and didn't even try to compile
- Clean up event channel code
- Clean up xen control code
- Add support for Device Tree loading via Linux Boot ABI
- Fixing crashing on userspace. Could be related to the patch series "arm SMP on Cortex-A15"
- Add guest SMP support
- DOM0 support?

Quoted 1 line

Any help, comments, questions are welcomed.

I think this is great! We'd love to work with you to make this happen.

Warner

Quoted 3 lines

Sincerely yours,

============= Instruction to test FreeBSD on Xen on ARM ===========

[trimmed]

Signature · 1 line
Julien Grall

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 55 lines · Julien Grall
Quoted 15 lines · Warner Losh
Quoted 14 lines · Julien Grall

This new support brings 2 open questions (for both Xen and FreeBSD community). When a new guest is created, the toolstack will generated a device tree which will contains:
- The amount of memory
- The description of the platform (gic, timer, hypervisor node)
- PSCI node for SMP bringup

Until now, Xen on ARM supported only Linux-based OS. When the support of device tree was added in Xen for guest, we chose to use Linux device tree bindings (gic, timer,...). It seems that FreeBSD choose a different way to implement device tree:
- strictly respect ePAR (for interrupt-parent property)
- gic bindings different (only 1 interrupt cell)

Quoted 7 lines
Quoted 4 lines

I would like to come with a common device tree specification (bindings, ...) across every operating system. I know the Linux community is working on having a device tree bindings out of the kernel tree. Does FreeBSD community plan to work with Linux community for this purpose?

We generally try to follow the common definitions for the FDT stuff. There are a few cases where we either lack the feature set of Linux, or where the Linux folks are moving quickly and changing the underlying

definitions

Quoted 1 line

where we wait for the standards to mature before we implement. In some

cases, where

Quoted 1 line

maturity hasn't happened, or where the bindings are overly Linux

centric (which in

Quoted 1 line

theory they aren't supposed to be, but sometimes wind up that way).

where we've not

Quoted 1 line

implemented things.

As I understand main bindings (gic, timer) are set in stone and won't change. Ian Campbell has a repository with all the ARM bindings here:
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;
a=tree;f=Bindings/arm

To compare the difference between the DT provided by Xen, and the one correctly parsed by FreeBSD
- Xen: http://xenbits.xen.org/people/julieng/xenvm-4.2.dts
- FreeBSD: http://xenbits.xen.org/people/julieng/xenvm-bsd.dts

Quoted 1 line

From Xen side:

- Every device should move under a simple-bus. I think it's harmless
for Linux side.
- How about hypervisor node? IHMO this node should also live under the
simple-bus.

Quoted 1 line

From FreeBSD side:

- GIC and Timer bindings needs to be handled correctly (see below the
problem for the GIC)
- Less stricter about interrupt-parent property. Eg, look at the
grant-parent if there is no property interrupt-parent
- If the hypervisor doesn't live under simple-bus, the interrupt/memory
retrieving should be moved from simple-bus to nexus?

Quoted 9 lines

Before the revision r260282 (I have added Nathan on cc), I was able to use the Linux GIC bindings (see
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;a=blob;f=Bindings/arm/gic.txt)
without any issue.

It seems the fdt bus, now consider the number of interrupt cells is always 1.

Thanks for the CC. Could you explain what you mean by "grant-parent" etc? "interrupt-parent" is a fundamental part of the way PAPR (and ePAPR) work, so I'm very very hesitant to start guessing. I think things have broken for you because some (a lot, actually) of OF code does not expect #interrupt-cells to be more than 2. Some APIs might need updating, which I'll try to take care of. Could you tell me what the difference between SPI and PPI is, by the way?

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices? -Nathan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 74 lines · Nathan Whitehorn
Quoted 63 lines · Julien Grall
Quoted 26 lines · Warner Losh
Quoted 18 lines · Julien Grall

This new support brings 2 open questions (for both Xen and FreeBSD community).
When a new guest is created, the toolstack will generated a device tree which
will contains:
- The amount of memory
- The description of the platform (gic, timer, hypervisor node)
- PSCI node for SMP bringup

Until now, Xen on ARM supported only Linux-based OS. When the support of device tree was added in Xen for guest, we chose to use Linux device tree
bindings (gic, timer,...). It seems that FreeBSD choose a different way to
implement device tree:
- strictly respect ePAR (for interrupt-parent property)
- gic bindings different (only 1 interrupt cell)

Quoted 7 lines

I would like to come with a common device tree specification (bindings, ...)
across every operating system. I know the Linux community is working on having
a device tree bindings out of the kernel tree. Does FreeBSD community plan to
work with Linux community for this purpose?

Quoted 3 lines

We generally try to follow the common definitions for the FDT stuff. There are a few cases where we either lack the feature set of Linux, or where the Linux folks are moving quickly and changing the underlying

definitions

Quoted 1 line

where we wait for the standards to mature before we implement. In some

cases, where

Quoted 1 line

maturity hasn't happened, or where the bindings are overly Linux

centric (which in

Quoted 1 line

theory they aren't supposed to be, but sometimes wind up that way).

where we've not

Quoted 1 line

implemented things.

As I understand main bindings (gic, timer) are set in stone and won't change. Ian Campbell has a repository with all the ARM bindings here:
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;
a=tree;f=Bindings/arm

To compare the difference between the DT provided by Xen, and the one correctly parsed by FreeBSD
- Xen: http://xenbits.xen.org/people/julieng/xenvm-4.2.dts
- FreeBSD: http://xenbits.xen.org/people/julieng/xenvm-bsd.dts

Quoted 1 line

From Xen side:

- Every device should move under a simple-bus. I think it's harmless
for Linux side.
- How about hypervisor node? IHMO this node should also live under the
simple-bus.

Quoted 1 line

From FreeBSD side:

- GIC and Timer bindings needs to be handled correctly (see below the
problem for the GIC)
- Less stricter about interrupt-parent property. Eg, look at the
grant-parent if there is no property interrupt-parent
- If the hypervisor doesn't live under simple-bus, the
interrupt/memory
retrieving should be moved from simple-bus to nexus?

Quoted 9 lines

Before the revision r260282 (I have added Nathan on cc), I was able to use the Linux GIC bindings (see
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;a=blob;f=Bindings/arm/gic.txt)
without any issue.

It seems the fdt bus, now consider the number of interrupt cells is always 1.

Quoted 6 lines

Thanks for the CC. Could you explain what you mean by "grant-parent" etc? "interrupt-parent" is a fundamental part of the way PAPR (and ePAPR) work, so I'm very very hesitant to start guessing. I think things have broken for you because some (a lot, actually) of OF code does not expect #interrupt-cells to be more than 2. Some APIs might need updating, which I'll try to take care of. Could you tell me what the difference between SPI and PPI is, by the way?

SPI: Shared Peripheral Interrupt
PPI: Private Peripheral Interrupt

PPIs are per processor interrupts.

Quoted 4 lines

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?

The PPI and the memory region advertized under the Xen hypervisor node on device tree are used to setup the basic infrastructure (grant table, event channels) needed by Xen paravirtualized devices.

#8 lore raw
In reply to a message not in the archive
Quoted 8 lines · Nathan Whitehorn

Thanks for the CC. Could you explain what you mean by "grant-parent" etc? "interrupt-parent" is a fundamental part of the way PAPR (and ePAPR) work, so I'm very very hesitant to start guessing. I think things have broken for you because some (a lot, actually) of OF code does not expect #interrupt-cells to be more than 2. Some APIs might need updating, which I'll try to take care of. Could you tell me what the difference between SPI and PPI is, by the way?

Sorry, I also made some typoes in my explanation so it was not clear.

interrupt-parent is a property in a device node which links this node to an interrupt controller (in our case the GIC controller).

The way to handle it on Linux and the ePAR is different:
- ePAR (chapter 2.4) says:
The physical wiring of an interrupt source to an interrupt controller is represented in the device tree with the interrupt-parent property. Nodes that represent interrupt-generating devices contain an interrupt-parent property which has a phandle value that points to the device to which the device's interrupts are routed, typically an interrupt controller. If an interrupt-generating device does not have an interrupt-parent property, its interrupt parent is assumed to be its device tree parent.
From my understanding, it's mandatory to have an interrupt-parent property on each device node which is using interrupts. If it doesn't exist it will assume that the parent is interrupt controller. If I'm mistaken, at least FreeBSD handle the interrupt-parent property in this way.
- Linux implementation will look at to the node, if the property
doesn't exists, it will check if the ancestor has this property ...

So the device tree below is valid on Linux, but not on FreeBSD:

/ {
interrupt-parent = &gic

  gic: gic@10
  {
    ...
  }

timer@1

  {
    interrupts = <...>

}
}

Most of shipped device tree use this trick.

IanC: I was reading the linux binding documentation (devicetree/booting-without-of.txt VII.2) and it seems that the explanation differs from the implementation, right?

For the #interrupt-cells property, the problem starts in fdt_intr_to_rl (sys/dev/fdt/fdt_common.c:476). ofw_bus_map_intr is called always with the first cells of the interrupt no matter the number of cells specified by #interrupt-cells.

Quoted 6 lines

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?
-Nathan

As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource.
So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

In the Xen device tree, we have an hypervisor node directly attach to the root which contains both MMIO and interrupt used by Xen to communicate with the guest.

Signature · 1 line
Julien Grall

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 41 lines · Julien Grall
Quoted 8 lines · Nathan Whitehorn

Thanks for the CC. Could you explain what you mean by "grant-parent" etc? "interrupt-parent" is a fundamental part of the way PAPR (and ePAPR) work, so I'm very very hesitant to start guessing. I think things have broken for you because some (a lot, actually) of OF code does not expect #interrupt-cells to be more than 2. Some APIs might need updating, which I'll try to take care of. Could you tell me what the difference between SPI and PPI is, by the way?

Sorry, I also made some typoes in my explanation so it was not clear.

interrupt-parent is a property in a device node which links this node to an interrupt controller (in our case the GIC controller).

The way to handle it on Linux and the ePAR is different:
- ePAR (chapter 2.4) says:
The physical wiring of an interrupt source to an interrupt controller is represented in the device tree with the interrupt-parent property. Nodes that represent interrupt-generating devices contain an interrupt-parent property which has a phandle value that points to the device to which the device's interrupts are routed, typically an interrupt controller. If an interrupt-generating device does not have an interrupt-parent property, its interrupt parent is assumed to be its device tree parent.
From my understanding, it's mandatory to have an interrupt-parent property on each device node which is using interrupts. If it doesn't exist it will assume that the parent is interrupt controller. If I'm mistaken, at least FreeBSD handle the interrupt-parent property in this way.
- Linux implementation will look at to the node, if the property
doesn't exists, it will check if the ancestor has this property ...

So the device tree below is valid on Linux, but not on FreeBSD:

/ {
interrupt-parent = &gic

  gic: gic@10
  {
    ...
  }

timer@1

  {
    interrupts = <...>
Quoted 8 lines

}
}

Most of shipped device tree use this trick.

IanC: I was reading the linux binding documentation (devicetree/booting-without-of.txt VII.2) and it seems that the explanation differs from the implementation, right?

For the #interrupt-cells property, the problem starts in fdt_intr_to_rl (sys/dev/fdt/fdt_common.c:476). ofw_bus_map_intr is called always with the first cells of the interrupt no matter the number of cells specified by #interrupt-cells.

The specification is actually a little unclear on this point, but FreeBSD follows the same rules as Linux in any case. Most, if not all, FreeBSD code should check any ancestor at this point as well. In particular fdt_intr_to_rl does this. What it *doesn't* do is allow #interrupt-cells to be larger than 2. I'll fix this this weekend.

Quoted 9 lines
Quoted 6 lines

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?
-Nathan

As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource.
So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

Quoted 2 lines

In the Xen device tree, we have an hypervisor node directly attach to the root which contains both MMIO and interrupt used by Xen to communicate with the guest.

OK. This should be fine, though simplebus would also work if you use MMIO. -Nathan

#11 lore raw
Quoted 7 lines · Nathan Whitehorn

On 01/16/14 18:36, Julien Grall wrote:

The specification is actually a little unclear on this point, but FreeBSD follows the same rules as Linux in any case. Most, if not all, FreeBSD code should check any ancestor at this point as well. In particular fdt_intr_to_rl does this. What it *doesn't* do is allow #interrupt-cells to be larger than 2. I'll fix this this weekend.

Thanks, for working on this part.

Another things to take into account: the first cell doesn't always contain the interrupt. With the Linux binding (#interrupt-cells == 3)
- cell 1: 1 or 0 (PPI vs SPI)
- cell 2: relative IRQ number to the start of PPI/SPI
- cell 3: cpu mask + interrupt flags (edge/level...)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?
-Nathan

Quoted 7 lines
Quoted 5 lines

As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have noticed at least one issue (which is not related to my problem):
- When the OFW nexus translate IRQ (with #interrupt-cells > 1), the
rid will be equal to 0, 0 + #interrupt-cells, ... So the number will be discontinued. Rather than on simple-bus for the same device, the rid will be 0, 1, 2...

For my issue, I will look at it again this week-end.

BTW when I look to the FDT (sys/dev/fdt_common.c) and the ofw (sys/dev/ofw_nexus.c) code, I have notice that lots of code are duplicated.

It would be nice to have common helper to avoid duplicate code and issue for the future :).

Signature · 1 line
Julien Grall

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 11 lines · Julien Grall
Quoted 7 lines · Nathan Whitehorn

On 01/16/14 18:36, Julien Grall wrote:

The specification is actually a little unclear on this point, but FreeBSD follows the same rules as Linux in any case. Most, if not all, FreeBSD code should check any ancestor at this point as well. In particular fdt_intr_to_rl does this. What it *doesn't* do is allow #interrupt-cells to be larger than 2. I'll fix this this weekend.

Quoted 8 lines

Thanks, for working on this part.

Another things to take into account: the first cell doesn't always contain the interrupt. With the Linux binding (#interrupt-cells == 3)
- cell 1: 1 or 0 (PPI vs SPI)
- cell 2: relative IRQ number to the start of PPI/SPI
- cell 3: cpu mask + interrupt flags (edge/level...)
`

Yep. This will require a little API redesign, but shouldn't be that bad.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?
-Nathan

As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Quoted 5 lines
Quoted 1 line

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have noticed at least one issue (which is not related to my problem):
- When the OFW nexus translate IRQ (with #interrupt-cells > 1), the
rid will be equal to 0, 0 + #interrupt-cells, ... So the number will be discontinued. Rather than on simple-bus for the same device, the rid will be 0, 1, 2...

Interesting. I'll investigate.

Quoted 6 lines

For my issue, I will look at it again this week-end.

BTW when I look to the FDT (sys/dev/fdt_common.c) and the ofw (sys/dev/ofw_nexus.c) code, I have notice that lots of code are duplicated.

It would be nice to have common helper to avoid duplicate code and issue for the future :).

I'm in the middle of cleaning all this up (which is how I'm on the hook for breaking your case!). Most of fdt_common.c is not long for this world. -Nathan

#14 lore raw
In reply to Nathan Whitehorn

Hello Nathan,

Quoted 11 lines · Nathan Whitehorn
Quoted 8 lines · Julien Grall

On 01/16/2014 01:56 AM, Nathan Whitehorn wrote:
As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have digged into the code to find the reason of my issue. FreeBSD is receiving a VM fault when the driver (xen-dt) is trying to setup the IRQ.

This is because the GIC is not yet initialized but FreeBSD asks to unmask the IRQ (sys/arm/arm/gic.c:306).

With this problem, all device nodes that are before the GIC in the device tree can't have interrupts. For instance this simple device will segfault on FreeBSD:

/ {

  mybus {
     compatible = "simple-bus";
     mynode {
        interrupt-parent = &gic;
        interrupts = <...>;
     };

     gic: gic@xxxx {
        interrupt-controller;
     }

};
};

The node "mynode" will have to move after the GIC to be able to work correctly.

Signature · 1 line
Julien Grall

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw
Quoted 39 lines · Julien Grall

Hello Nathan,

Quoted 11 lines · Nathan Whitehorn
Quoted 8 lines · Julien Grall

On 01/16/2014 01:56 AM, Nathan Whitehorn wrote:
As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have digged into the code to find the reason of my issue. FreeBSD is receiving a VM fault when the driver (xen-dt) is trying to setup the IRQ.

This is because the GIC is not yet initialized but FreeBSD asks to unmask the IRQ (sys/arm/arm/gic.c:306).

With this problem, all device nodes that are before the GIC in the device tree can't have interrupts. For instance this simple device will segfault on FreeBSD:

/ {

  mybus {
     compatible = "simple-bus";
     mynode {
        interrupt-parent = &gic;
        interrupts = <...>;
     };

     gic: gic@xxxx {
        interrupt-controller;
     }
Quoted 6 lines

};
};

The node "mynode" will have to move after the GIC to be able to work correctly.

Ah, that sounds like a bug in the interrupt handling code. The PPC code is designed to handle this problem by deferring interrupt setup, as well as a number of other latent issues, and I think would make a good match for ARM as well. I made an experimental branch to port it to MIPS (the code is almost entirely machine-independent) but am waiting for testing. A general solution to this problem has to involve deferred setup. -Nathan

#17 lore raw
In reply to a message not in the archive
Quoted 35 lines · Julien Grall

Hello Nathan,

Quoted 11 lines · Nathan Whitehorn
Quoted 8 lines · Julien Grall

On 01/16/2014 01:56 AM, Nathan Whitehorn wrote:
As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have digged into the code to find the reason of my issue. FreeBSD is receiving a VM fault when the driver (xen-dt) is trying to setup the IRQ.

This is because the GIC is not yet initialized but FreeBSD asks to unmask the IRQ (sys/arm/arm/gic.c:306).

With this problem, all device nodes that are before the GIC in the device tree can't have interrupts. For instance this simple device will segfault on FreeBSD:

/ {

 mybus {
    compatible = "simple-bus";

    mynode {
       interrupt-parent = &gic;
       interrupts = <...>;
    };

    gic: gic@xxxx {
       interrupt-controller;
    }
Quoted 4 lines

};
};

The node "mynode" will have to move after the GIC to be able to work correctly.

This stems from a difference in enumeration between FreeBSD and Linux. FreeBSD enumerates the devices in DTB order, while Linux does a partial ordering based on dependencies.

Warner

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 36 lines · Warner Losh
Quoted 34 lines · Julien Grall

Hello Nathan,

Quoted 9 lines · Nathan Whitehorn
Quoted 7 lines · Julien Grall

On 01/16/2014 01:56 AM, Nathan Whitehorn wrote:
As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have digged into the code to find the reason of my issue. FreeBSD is receiving a VM fault when the driver (xen-dt) is trying to setup the IRQ.

This is because the GIC is not yet initialized but FreeBSD asks to unmask the IRQ (sys/arm/arm/gic.c:306).

With this problem, all device nodes that are before the GIC in the device tree can't have interrupts. For instance this simple device will segfault on FreeBSD:

/ {

 mybus {
    compatible = "simple-bus";

    mynode {
       interrupt-parent = &gic;
       interrupts = <...>;
    };

    gic: gic@xxxx {
       interrupt-controller;
    }

};
};

Quoted 4 lines
Quoted 1 line

The node "mynode" will have to move after the GIC to be able to work correctly.

This stems from a difference in enumeration between FreeBSD and Linux. FreeBSD enumerates the devices in DTB order, while Linux does a partial ordering based on dependencies.

Warner

Enumerating in some other order doesn't necessarily help: since the interrupt and bus trees are independent, circular dependencies can happen. This is not a hypothetical: on most powermacs, the main interrupt controller is a functional unit on a PCI device -- a PCI device whose other units have interrupt lines that eventually connect back to itself. There is no way to fix that with ordering. So I think we still need to defer interrupt setup. It's not that bad -- PPC already does this to handle the powermac case.
-Nathan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#21 lore raw
Quoted 42 lines · Nathan Whitehorn
Quoted 36 lines · Warner Losh
Quoted 34 lines · Julien Grall

Hello Nathan,

Quoted 9 lines · Nathan Whitehorn
Quoted 7 lines · Julien Grall

On 01/16/2014 01:56 AM, Nathan Whitehorn wrote:
As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have digged into the code to find the reason of my issue. FreeBSD is receiving a VM fault when the driver (xen-dt) is trying to setup the IRQ.

This is because the GIC is not yet initialized but FreeBSD asks to unmask the IRQ (sys/arm/arm/gic.c:306).

With this problem, all device nodes that are before the GIC in the device tree can't have interrupts. For instance this simple device will segfault on FreeBSD:

/ {

mybus {
   compatible = "simple-bus";

   mynode {
      interrupt-parent = &gic;
      interrupts = <...>;
   };

   gic: gic@xxxx {
      interrupt-controller;
   }
};

};

Quoted 4 lines
Quoted 1 line

The node "mynode" will have to move after the GIC to be able to work correctly.

This stems from a difference in enumeration between FreeBSD and Linux. FreeBSD enumerates the devices in DTB order, while Linux does a partial ordering based on dependencies.

Warner

Quoted 8 lines

Enumerating in some other order doesn't necessarily help: since the interrupt and bus trees are independent, circular dependencies can happen. This is not a hypothetical: on most powermacs, the main interrupt controller is a functional unit on a PCI device -- a PCI device whose other units have interrupt lines that eventually connect back to itself. There is no way to fix that with ordering. So I think we still need to defer interrupt setup. It's not that bad -- PPC already does this to handle the powermac case.

I guess I've looked at simpler cases where interrupts and GPIO pins need to be up before anything can work on Atmel... We kinda fake it now, but there's some ordering issues that are solved in this way. But I've not finished the work on bringing Atmel into the FDT world yet. Deferred setup isn't always an option, but I'll keep that in mind in case I hit that case...

The other way to cope is to use the multi-pass enumeration stuff that John Baldwin put into the tree a while ago. In that case, you could enumerate bridges, interrupt controllers, gpio providers, etc first, and then do a second pass that catches the rest of the devices and the interrupt processing for the first pass devices. This is a variation on the deferred enumeration stuff you are talking about, so that might be a better, more general solution to these sorts of problems.

Warner

A message that is not in the archive (sent off-list or not yet received): [email protected]

#23 lore raw
Quoted 50 lines · Warner Losh
Quoted 40 lines · Nathan Whitehorn
Quoted 35 lines · Warner Losh
Quoted 33 lines · Julien Grall

Hello Nathan,

Quoted 8 lines · Nathan Whitehorn
Quoted 6 lines · Julien Grall

On 01/16/2014 01:56 AM, Nathan Whitehorn wrote:
As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource. So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Why not? nexus on ARM, MIPS, PowerPC, and sparc64 can do this.

I have digged into the code to find the reason of my issue. FreeBSD is receiving a VM fault when the driver (xen-dt) is trying to setup the IRQ.

This is because the GIC is not yet initialized but FreeBSD asks to unmask the IRQ (sys/arm/arm/gic.c:306).

With this problem, all device nodes that are before the GIC in the device tree can't have interrupts. For instance this simple device will segfault on FreeBSD:

/ {

mybus {
   compatible = "simple-bus";

   mynode {
      interrupt-parent = &gic;
      interrupts = <...>;
   };

   gic: gic@xxxx {
      interrupt-controller;
   }
};

};

Quoted 4 lines
Quoted 1 line

The node "mynode" will have to move after the GIC to be able to work correctly.

This stems from a difference in enumeration between FreeBSD and Linux. FreeBSD enumerates the devices in DTB order, while Linux does a partial ordering based on dependencies.

Warner

Quoted 8 lines

Enumerating in some other order doesn't necessarily help: since the interrupt and bus trees are independent, circular dependencies can happen. This is not a hypothetical: on most powermacs, the main interrupt controller is a functional unit on a PCI device -- a PCI device whose other units have interrupt lines that eventually connect back to itself. There is no way to fix that with ordering. So I think we still need to defer interrupt setup. It's not that bad -- PPC already does this to handle the powermac case.

Quoted 7 lines

I guess I've looked at simpler cases where interrupts and GPIO pins need to be up before anything can work on Atmel... We kinda fake it now, but there's some ordering issues that are solved in this way. But I've not finished the work on bringing Atmel into the FDT world yet. Deferred setup isn't always an option, but I'll keep that in mind in case I hit that case...

The other way to cope is to use the multi-pass enumeration stuff that John Baldwin put into the tree a while ago. In that case, you could enumerate bridges, interrupt controllers, gpio providers, etc first, and then do a second pass that catches the rest of the devices and the interrupt processing for the first pass devices. This is a variation on the deferred enumeration stuff you are talking about, so that might be a better, more general solution to these sorts of problems.

Warner

I'm still not sure that helps. Take the powermac case. The PCI parent bridge assigns and routes interrupts as part of its probe stage. One device (called mac-io) is the one that actually has the interrupt controller, along with other things like ATA and sound. It has several interrupts to support e.g. ATA. How can the PCI bus attachment sensibly attach the macio device? If it delays attaching it until the interrupt controller registers, the bus probing will deadlock, since the interrupt controller is itself a child of macio! If it attaches it immediately, it will not be able to route the interrupts of the macio device. It's a catch-22.

The only solution we were able to come up with when this situation arose was to treat the bus and interrupt trees as entirely separate things, built independently, which allows the kernel to break the loop. GPIOs can have similar problems. The basic issue is that newbus ultimately assumes that the system topology can be described by a single tree. Interconnections between the branches -- especially if it isn't even a DAG -- fundamentally break the model and multipass doesn't necessarily help. -Nathan

#24 lore raw
In reply to a message not in the archive
Quoted 50 lines · Julien Grall
Quoted 8 lines · Nathan Whitehorn

Thanks for the CC. Could you explain what you mean by "grant-parent" etc? "interrupt-parent" is a fundamental part of the way PAPR (and ePAPR) work, so I'm very very hesitant to start guessing. I think things have broken for you because some (a lot, actually) of OF code does not expect #interrupt-cells to be more than 2. Some APIs might need updating, which I'll try to take care of. Could you tell me what the difference between SPI and PPI is, by the way?

Sorry, I also made some typoes in my explanation so it was not clear.

interrupt-parent is a property in a device node which links this node to an interrupt controller (in our case the GIC controller).

The way to handle it on Linux and the ePAR is different:
- ePAR (chapter 2.4) says:
The physical wiring of an interrupt source to an interrupt controller is represented in the device tree with the interrupt-parent property. Nodes that represent interrupt-generating devices contain an interrupt-parent property which has a phandle value that points to the device to which the device's interrupts are routed, typically an interrupt controller. If an interrupt-generating device does not have an interrupt-parent property, its interrupt parent is assumed to be its device tree parent.
From my understanding, it's mandatory to have an interrupt-parent
property on each device node which is using interrupts. If it doesn't exist it will assume that the parent is interrupt controller. If I'm mistaken, at least FreeBSD handle the interrupt-parent property in this way.
- Linux implementation will look at to the node, if the property
doesn't exists, it will check if the ancestor has this property ...

So the device tree below is valid on Linux, but not on FreeBSD:

/ {
   interrupt-parent = &gic

   gic: gic@10
   {
     ...
   }

   timer@1
   {
     interrupts = <...>
   }
}
Quoted 5 lines

Most of shipped device tree use this trick.

IanC: I was reading the linux binding documentation (devicetree/booting-without-of.txt VII.2) and it seems that the explanation differs from the implementation, right?

I vaguely recall someone saying that the Linux behaviour was a quirk of some real PPC system which supplied a DTB which required this behaviour which has leaked into the other platforms. It does also sound like a useful extension to the spec which makes the dtb easier to write.

The right place to discuss this would probably be either #devicetree on freenode or [email protected].

Quoted 7 lines
Quoted 6 lines

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?
-Nathan

Quoted 5 lines

As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource.
So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Is the root node not considered to be a "top-level simple-bus" with a 1:1 mapping of MMIO and interrupts? (Linux seems to treat it this way, but I haven't trawled the docs for a spec reference to back that behaviour up). I take it BSD doesn't do this?

Ian.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#26 lore raw
Quoted 16 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Quoted 6 lines · Nathan Whitehorn

On the subject of simple-bus, they usually aren't necessary. For example, all hypervisor devices on IBM hardware live under /vdevice, which is attached to the device tree root. They don't use MMIO, so simple-bus doesn't really make sense. How does Xen communicate with the OS in these devices?
-Nathan

Quoted 5 lines

As I understand, only the simple bus code (see simplebus_attach) is translating the interrupts in the device on a resource.
So if you have a node directly attached to the root node with interrupts and MMIO, the driver won't be able to retrieve and translate the interrupts via bus_alloc_resources.

Quoted 4 lines

Is the root node not considered to be a "top-level simple-bus" with a 1:1 mapping of MMIO and interrupts? (Linux seems to treat it this way, but I haven't trawled the docs for a spec reference to back that behaviour up). I take it BSD doesn't do this?

There is 2 different paths on FreeBSD to decode interrupt/MMIO (depending if you are under the root node or a simple-bus node). Most of the code is duplicated but there are some parts which differs (for instance interrupt decoding, see my answer to Nathan).

I will look at closer to the code this week-end and see if I can fix it.

Signature · 1 line
Julien Grall
#27 lore raw
In reply to a message not in the archive
Quoted 9 lines · Ian Campbell
Quoted 3 lines · Julien Grall

IanC: I was reading the linux binding documentation (devicetree/booting-without-of.txt VII.2) and it seems that the explanation differs from the implementation, right?

I vaguely recall someone saying that the Linux behaviour was a quirk of some real PPC system which supplied a DTB which required this behaviour which has leaked into the other platforms. It does also sound like a useful extension to the spec which makes the dtb easier to write.

I've read twice the ePAR and did some test. I was completely wrong, this file is valid with the ePAR (there is even an example like that at the end at the specification). And FreeBSD doesn't complain about this since Nathan's ofw/fdt rework.

Sorry for the waste time.

Signature · 1 line
Julien Grall
#28 lore raw
In reply to a message not in the archive
Quoted 3 lines · Julien Grall

As I understand main bindings (gic, timer) are set in stone and won't change. Ian Campbell has a repository with all the ARM bindings here:
http://xenbits.xen.org/gitweb/?p=people/ianc/device-tree-rebasing.git;a=tree;f=Bindings/arm

FYI this tree is automatically extracted from the bindings in the Linux source, because long term we would like to split them out from Linux and try and standardize some (if not all) of them. This is exactly because these bindings should not be OS specific...

Ian.