From patchwork Fri Mar 3 23:28:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 735253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vZlqS5SXNz9s2s for ; Sat, 4 Mar 2017 10:33:24 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vZlqS4MJvzDqGp for ; Sat, 4 Mar 2017 10:33:24 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vZlqN6X12zDqBV for ; Sat, 4 Mar 2017 10:33:20 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v23NSfWD142287 for ; Fri, 3 Mar 2017 18:33:18 -0500 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 28xs8g6ry2-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 03 Mar 2017 18:33:18 -0500 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Mar 2017 18:33:17 -0500 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 3 Mar 2017 18:33:15 -0500 Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 31468C9001C; Fri, 3 Mar 2017 18:32:55 -0500 (EST) Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v23NXCgx38863066; Fri, 3 Mar 2017 23:33:14 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91C2012404E; Fri, 3 Mar 2017 18:33:12 -0500 (EST) Received: from localhost (unknown [9.80.106.253]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP id 576A612403D; Fri, 3 Mar 2017 18:33:12 -0500 (EST) From: Michael Roth To: slof@lists.ozlabs.org Date: Fri, 3 Mar 2017 17:28:11 -0600 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17030323-0040-0000-0000-000002C6F9AC X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006717; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00829729; UDB=6.00406810; IPR=6.00607226; BA=6.00005186; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014514; XFM=3.00000012; UTC=2017-03-03 23:33:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17030323-0041-0000-0000-000006BB0060 Message-Id: <1488583692-31827-1-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-03_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=43 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703030205 Subject: [SLOF] [PATCH v2] pci: force minimum mem bar alignment of 64K for board-qemu X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This is needed to ensure VFIO passthrough devices are able to offload MMIO accesses to KVM. Cc: Segher Boessenkool Cc: Nikunj A Dadhania Cc: David Gibson Signed-off-by: Michael Roth --- v2: * default to 0 min-align instead of 64K (David) * refactor assign-var* for readability (Segher) * add/utilize umax instead of max (Segher) --- board-qemu/slof/pci-phb.fs | 4 ++++ slof/engine.in | 1 + slof/fs/pci-properties.fs | 38 ++++++++++++++++++++++++++++++-------- slof/fs/pci-scan.fs | 3 +++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/board-qemu/slof/pci-phb.fs b/board-qemu/slof/pci-phb.fs index 667514e..698bf5a 100644 --- a/board-qemu/slof/pci-phb.fs +++ b/board-qemu/slof/pci-phb.fs @@ -331,6 +331,10 @@ setup-puid my-puid TO puid \ Set current puid phb-parse-ranges 1 TO pci-hotplug-enabled + s" qemu,mem-bar-min-align" get-node get-property 0= IF + decode-int TO pci-mem-bar-min-align + 2drop + THEN s" qemu,phb-enumerated" get-node get-property 0<> IF 1 0 (probe-pci-host-bridge) ELSE diff --git a/slof/engine.in b/slof/engine.in index 0344a38..549e409 100644 --- a/slof/engine.in +++ b/slof/engine.in @@ -145,6 +145,7 @@ col(D2/ >R U2/ R@ LIT(8*CELLSIZE-1) LSHIFT OR R> 2/) col(NEGATE 0 SWAP -) col(ABS DUP 0< 0BRANCH(1) NEGATE) col(MAX 2DUP < 0BRANCH(1) SWAP DROP) +col(UMAX 2DUP U< 0BRANCH(1) SWAP DROP) col(MIN 2DUP > 0BRANCH(1) SWAP DROP) col(U* *) col(1+ 1 +) diff --git a/slof/fs/pci-properties.fs b/slof/fs/pci-properties.fs index 7faa714..e6fd843 100644 --- a/slof/fs/pci-properties.fs +++ b/slof/fs/pci-properties.fs @@ -91,17 +91,37 @@ \ *************************************************************************************** \ align the current mem and set var to next mem \ align with a size of 0 returns 0 !!! -: assign-var ( size var -- al-mem ) - 2dup @ \ ( size var size cur-mem ) read current free mem - swap #aligned \ ( size var al-mem ) align the mem to the size - dup 2swap -rot + \ ( al-mem var new-mem ) add size to aligned mem - swap ! \ ( al-mem ) set variable to new mem +: assign-var-align ( size align var -- al-mem ) + dup >r @ \ ( size align cur-mem ) + swap #aligned \ ( size al-mem ) + tuck + \ ( al-mem new-mem ) + r> ! \ ( al-mem ) +; + +: assign-var-min-align ( size min-align var -- al-mem ) + >r over umax \ ( size align ) + r> assign-var-align \ ( al-mem ) ; \ set bar to current free mem ( in variable ) and set variable to next free mem : assign-bar-value32 ( bar size var -- 4 ) over IF \ IF size > 0 - assign-var \ | ( bar al-mem ) set variable to next mem + >r \ | ( bar size ) + pci-mem-bar-min-align \ | ( bar size min-align ) + r> assign-var-min-align \ | ( bar al-mem ) set variable to next mem + swap rtas-config-l! \ | ( -- ) set the bar to al-mem + ELSE \ ELSE + 2drop drop \ | clear stack + THEN \ FI + 4 \ size of the base-address-register +; + +\ set bar to current free mem ( in variable ) and set variable to next free mem +: assign-io-bar-value32 ( bar size var -- 4 ) + over IF \ IF size > 0 + >r \ | ( bar size ) + dup \ | ( bar size size-align ) + r> assign-var-align \ | ( bar al-mem ) set variable to next mem swap rtas-config-l! \ | ( -- ) set the bar to al-mem ELSE \ ELSE 2drop drop \ | clear stack @@ -112,7 +132,9 @@ \ set bar to current free mem ( in variable ) and set variable to next free mem : assign-bar-value64 ( bar size var -- 8 ) over IF \ IF size > 0 - assign-var \ | ( bar al-mem ) set variable to next mem + >r \ | ( bar size ) + pci-mem-bar-min-align \ | ( bar size min-align ) + r> assign-var-min-align \ | ( bar al-mem ) set variable to next mem swap \ | ( al-mem addr ) calc config-addr of this bar 2dup rtas-config-l! \ | ( al-mem addr ) set the Lower part of the bar to al-mem 4 + swap 20 rshift \ | ( al-mem>>32 addr ) prepare the upper part of the al-mem @@ -163,7 +185,7 @@ : assign-io-bar ( bar-addr -- 4 ) dup pci-bar-size-io \ fetch size pci-next-io \ var to change - assign-bar-value32 \ and set it all + assign-io-bar-value32 \ and set it all ; \ Setup an Expansion ROM bar diff --git a/slof/fs/pci-scan.fs b/slof/fs/pci-scan.fs index a528c8e..bd8cc0d 100644 --- a/slof/fs/pci-scan.fs +++ b/slof/fs/pci-scan.fs @@ -24,6 +24,9 @@ VARIABLE pci-max-io VARIABLE pci-next-mem64 \ prefetchable 64-bit memory mapped VARIABLE pci-max-mem64 +\ 0 to default to natural alignment +0 VALUE pci-mem-bar-min-align + \ Counter of busses found 0 VALUE pci-bus-number \ Counter of devices found