From c1394c3d2a8af1b64dd677f3b572236109fe453d Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Tue, 10 Jan 2012 22:39:42 +1100 Subject: Support new-style PCI for qemu board We now support populating the device-nodes ourselves when using a newer qemu which doesn't do it anymore. Note: I have removed the support for working with the existing device nodes, so qemu needs to be updated in sync with slof Signed-off-by: Benjamin Herrenschmidt --- board-qemu/slof/pci-capabilities.fs | 4 ++ board-qemu/slof/pci-interrupts.fs | 8 ++++ board-qemu/slof/pci-phb.fs | 88 +++++++++++++++++++++++++++++-------- board-qemu/slof/rtas.fs | 5 ++- board-qemu/slof/tree.fs | 2 + slof/fs/pci-properties.fs | 4 ++ slof/fs/pci-scan.fs | 17 ++++--- 7 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 board-qemu/slof/pci-capabilities.fs create mode 100644 board-qemu/slof/pci-interrupts.fs diff --git a/board-qemu/slof/pci-capabilities.fs b/board-qemu/slof/pci-capabilities.fs new file mode 100644 index 0000000..9ac580d --- /dev/null +++ b/board-qemu/slof/pci-capabilities.fs @@ -0,0 +1,4 @@ +\ Set up all known capabilities for this board to the plugged devices +: pci-set-capabilities ( config-addr -- ) + drop +; diff --git a/board-qemu/slof/pci-interrupts.fs b/board-qemu/slof/pci-interrupts.fs new file mode 100644 index 0000000..11db05f --- /dev/null +++ b/board-qemu/slof/pci-interrupts.fs @@ -0,0 +1,8 @@ +: pci-gen-irq-entry ( prop-addr prop-len config-addr -- prop-addr prop-len ) + ." SHOULD NOT GET THERE !" cr + drop +; + +: pci-set-irq-line ( config-addr -- ) + drop +; diff --git a/board-qemu/slof/pci-phb.fs b/board-qemu/slof/pci-phb.fs index 62bc281..5b63eb2 100644 --- a/board-qemu/slof/pci-phb.fs +++ b/board-qemu/slof/pci-phb.fs @@ -107,12 +107,18 @@ setup-puid 0 VALUE dma-window-size \ Size of the window \ Read helper variables (LIOBN, DMA window base and size) from the -\ "ibm,dma-window" property. This property is unfortunately currently located -\ in the PCI device node instead of the bus node, so we've got to use the +\ "ibm,dma-window" property. This property can be either located +\ in the PCI device node or in the bus node, so we've got to use the \ "calling-child" variable here to get to the node that initiated the call. +\ XXX We should search all the way up the tree to the PHB ... : (init-dma-window-vars) ( -- ) - s" ibm,dma-window" calling-child - get-property ABORT" no dma-window property available" +\ ." Foo called in " pwd cr +\ ." calling child is " calling-child .node cr +\ ." parent is " calling-child parent .node cr + s" ibm,dma-window" calling-child get-property IF + s" ibm,dma-window" calling-child parent get-property + ABORT" no dma-window property available" + THEN decode-int TO dma-window-liobn decode-64 TO dma-window-base decode-64 TO dma-window-size @@ -179,25 +185,69 @@ setup-puid : open true ; : close ; +\ Parse the "ranges" property of the root pci node to decode the available +\ memory ranges. See "PCI Bus Binding to IEEE Std 1275-1994" for details. +\ The memory ranges are then used for setting up the device bars (if necessary) +: phb-parse-ranges ( -- ) + \ First clear everything, in case there is something missing in the ranges + 0 pci-next-io ! + 0 pci-max-io ! + 0 pci-next-mem ! + 0 pci-max-mem ! + 0 pci-next-mmio ! + 0 pci-max-mmio ! + + \ Now get the "ranges" property + s" ranges" get-node get-property 0<> ABORT" ranges property not found" + ( prop-addr prop-len ) + BEGIN + dup + WHILE + decode-int \ Decode phys.hi + 3000000 AND \ Filter out address space in phys.hi + CASE + 1000000 OF \ I/O space? + decode-64 dup >r pci-next-io ! \ Decode PCI base address + decode-64 drop \ Forget the parent address + decode-64 r> + pci-max-io ! \ Decode size & calc max address + pci-next-io @ 0= IF + pci-next-io @ 10 + pci-next-io ! \ BARs must not be set to zero + THEN + ENDOF + 2000000 OF \ 32-bit memory space? + decode-64 pci-next-mem ! \ Decode mem base address + decode-64 drop \ Forget the parent address + decode-64 2 / dup >r \ Decode and calc size/2 + pci-next-mem @ + dup pci-max-mem ! \ and calc max mem address + dup pci-next-mmio ! \ which is the same as MMIO base + r> + pci-max-mmio ! \ calc max MMIO address + ENDOF + 3000000 OF \ 64-bit memory space? + cr ." Warning: 64-bit PCI space not supported yet! " + decode-64 . decode-64 . cr + ENDOF + ENDCASE + REPEAT + ( prop-addr prop-len ) + 2drop + + phb-debug? IF + ." pci-next-io = " pci-next-io @ . cr + ." pci-max-io = " pci-max-io @ . cr + ." pci-next-mem = " pci-next-mem @ . cr + ." pci-max-mem = " pci-max-mem @ . cr + ." pci-next-mmio = " pci-next-mmio @ . cr + ." pci-max-mmio = " pci-max-mmio @ . cr + THEN +; \ Scan the child nodes of the pci root node to assign bars, fixup \ properties etc. -: setup-children +: phb-setup-children puid >r \ Save old value of puid my-puid TO puid \ Set current puid - get-node child - BEGIN - dup \ Continue as long as there are children - WHILE - \ ." Working on " dup node>path type cr - \ Set child node as current node: - dup set-node - \ Include the PCI device functions: - s" pci-device.fs" included - peer ( next-child-phandle ) - REPEAT - drop + phb-parse-ranges + ff 0 (probe-pci-host-bridge) r> TO puid \ Restore previous puid ; - -setup-children +phb-setup-children diff --git a/board-qemu/slof/rtas.fs b/board-qemu/slof/rtas.fs index e1c357a..a366ad7 100644 --- a/board-qemu/slof/rtas.fs +++ b/board-qemu/slof/rtas.fs @@ -122,8 +122,9 @@ find-qemu-rtas ( addr ) rtas-cb rtas>args0 l! enter-rtas rtas-cb rtas>args4 l@ dup IF - ." RTAS config err " . cr - ffffffff + \ Do not warn on error as this is part of the + \ normal PCI probing pass + drop ffffffff ELSE drop rtas-cb rtas>args5 l@ THEN diff --git a/board-qemu/slof/tree.fs b/board-qemu/slof/tree.fs index 6b7b961..533fc95 100644 --- a/board-qemu/slof/tree.fs +++ b/board-qemu/slof/tree.fs @@ -95,6 +95,8 @@ populate-vios 5a0 cp +#include "pci-scan.fs" + : populate-pci-busses ( -- ) \ Populate the /pci* children with their methods " /" find-device get-node child diff --git a/slof/fs/pci-properties.fs b/slof/fs/pci-properties.fs index 312f431..0e67a18 100644 --- a/slof/fs/pci-properties.fs +++ b/slof/fs/pci-properties.fs @@ -604,7 +604,11 @@ pci-device-slots encode-int s" slot-names" property dup pci-bridge-range-props dup pci-bridge-assigned-addresses-prop + \ Only create interrupt-map when it doesn't already exist + \ (it can be provided by qemu) + s" interrupt-map" get-node get-property IF pci-bridge-interrupt-map + ELSE 2drop THEN pci-reg-props ; diff --git a/slof/fs/pci-scan.fs b/slof/fs/pci-scan.fs index 9114670..1132751 100644 --- a/slof/fs/pci-scan.fs +++ b/slof/fs/pci-scan.fs @@ -297,6 +297,15 @@ DEFER func-pci-probe-bus LOOP \ else next bus ; +: (probe-pci-host-bridge) ( bus-max bus-min -- ) + 0d emit ." Adapters on " puid 10 0.r cr \ print the puid we're looking at + ( bus-max bus-min ) pci-probe-all \ and walk the bus + pci-device-number 0= IF \ IF no devices found + 15 spaces \ | indent the output + ." None" cr \ | tell the world our result + THEN \ FI +; + \ probe the hostbridge that is specified in my-puid \ for the mmio mem and io addresses: \ base is the least available address @@ -309,13 +318,7 @@ DEFER func-pci-probe-bus pci-max-mem ! \ save the max mem-space address pci-next-mmio ! \ save the next mmio-base address pci-max-mmio ! \ save the max mmio-space address - - 0d emit ." Adapters on " puid 10 0.r cr \ print the puid we're looking at - ( bus-max bus-min ) pci-probe-all \ and walk the bus - pci-device-number 0= IF \ IF no devices found - 15 spaces \ | indent the output - ." None" cr \ | tell the world our result - THEN \ FI + (probe-pci-host-bridge) r> TO puid \ restore puid ; -- cgit v1.1