From patchwork Fri Jul 21 07:35:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 791945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xDMyW3Bjlz9s3T for ; Fri, 21 Jul 2017 17:36:19 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xDMyW1nbkzDqtt for ; Fri, 21 Jul 2017 17:36:19 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from ozlabs.ru (ozlabs.ru [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 3xDMyN6srXzDqrw for ; Fri, 21 Jul 2017 17:36:12 +1000 (AEST) Received: from vpl2.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id F32103A6002F; Fri, 21 Jul 2017 03:36:33 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Fri, 21 Jul 2017 17:35:35 +1000 Message-Id: <20170721073537.16095-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170721073537.16095-1-aik@ozlabs.ru> References: <20170721073537.16095-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof 1/3] pci-scan: Move bits around 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 rearranges code to make next patch simpler. While we are here, this makes one functional change: in addition to checking the config space for 64bit support, this also checks pci-next-mem64. This should cause no behavioral change. Signed-off-by: Alexey Kardashevskiy --- slof/fs/pci-scan.fs | 95 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/slof/fs/pci-scan.fs b/slof/fs/pci-scan.fs index c39707a..7bc6b98 100644 --- a/slof/fs/pci-scan.fs +++ b/slof/fs/pci-scan.fs @@ -104,47 +104,80 @@ here 100 allot CONSTANT pci-device-vec or swap 20 + rtas-config-l! \ and write it into the Reg ; +: pci-bridge-support-mem64 ( addr -- 1|0 ) + 24 + rtas-config-w@ 1 and \ does bridge support 64-bit? +; + +: pci-bridge-has-mem64 ( addr -- 1|0 ) + pci-bridge-support-mem64 + pci-next-mem64 @ 0<> and +; + +: pci-next-mem-align-1mb ( -- pci-next-mem ) + pci-next-mem + 100000 #aligned \ align to 1MB boundary + dup pci-next-mem ! +; + +: pci-next-mem-extend-1mb ( -- pci-next-mem ) + pci-next-mem @ + 100000 + \ add space for hot-plugging + 100000 #aligned \ align to 1MB boundary + dup pci-next-mem ! +; + \ Update pci-next-mem to be 1MB aligned and set the mem-base and mem-base-upper register \ and set the Limit register to the maximum available address space \ needed for scanning possible devices behind the bridge : pci-bridge-set-mem-base ( addr -- ) - pci-next-mem @ 100000 #aligned \ read the current Value and align to 1MB boundary - dup pci-next-mem ! \ and write it back - over 24 + rtas-config-w@ \ check if 64bit support - 1 and IF \ IF 64 bit support - pci-next-mem64 @ 100000000 #aligned \ | read the current Value of 64-bit and align to 4GB boundary - dup 100000000 + pci-next-mem64 x! \ | and write back with 1GB for bridge - 2 pick swap \ | - 20 rshift \ | keep upper 32 bits - swap 28 + rtas-config-l! \ | and write it into the Base-Upper32-bits - pci-max-mem64 @ 20 rshift \ | fetch max Limit address and keep upper 32 bits - 2 pick 2C + rtas-config-l! \ | and set the Limit - THEN \ FI - 10 rshift \ keep upper 16 bits - pci-max-mem @ 1- FFFF0000 and or \ and Insert mmem Limit (set it to max) - swap 24 + rtas-config-l! \ and write it into the bridge + dup pci-bridge-has-mem64 \ check if 64bit support + IF \ IF 64 bit support + pci-next-mem-align-1mb + pci-next-mem64 @ 100000000 #aligned \ | read the current Value of 64-bit and align to 4GB boundary + dup 100000000 + pci-next-mem64 x! \ | and write back with 1GB for bridge + 2 pick swap \ | + 20 rshift \ | keep upper 32 bits + swap 28 + rtas-config-l! \ | and write it into the Base-Upper32-bits + pci-max-mem64 @ 20 rshift \ | fetch max Limit address and keep upper 32 bits + 2 pick 2C + rtas-config-l! \ | and set the Limit + 10 rshift \ | keep upper 16 bits + pci-max-mem @ 1- FFFF0000 and or \ | and Insert mmem Limit (set it to max) + swap 24 + rtas-config-l! \ | and write it into the bridge + ELSE + pci-next-mem-align-1mb + 10 rshift \ | keep upper 16 bits + pci-max-mem @ 1- FFFF0000 and or \ | and Insert mmem Limit (set it to max) + swap 24 + rtas-config-l! \ | and write it into the bridge + THEN ; \ Update pci-next-mem to be 1MB aligned and set the mem-limit register \ The Limit Value is one less then the upper boundary \ If the limit is less than the base the mem is disabled : pci-bridge-set-mem-limit ( addr -- ) - pci-next-mem @ 100000 + \ add space for hot-plugging - 100000 #aligned \ align to 1MB boundary - dup pci-next-mem ! \ and write it back - 1- \ make limit one less than boundary - over 24 + rtas-config-w@ \ check if 64bit support - 1 and IF \ IF 64 bit support - pci-next-mem64 @ 100000000 #aligned \ | Reat current value of 64-bar and align at 4GB - dup pci-next-mem64 x! \ | and write it back - 1- \ | make limite one less than boundary - 2 pick swap \ | - 20 rshift \ | keep upper 32 bits - swap 2C + rtas-config-l! \ | and write it into the Limit-Upper32-bits - THEN \ FI - FFFF0000 and \ keep upper 16 bits - over 24 + rtas-config-l@ 0000FFFF and \ fetch original Value - or swap 24 + rtas-config-l! \ and write it into the bridge + dup pci-bridge-has-mem64 \ check if 64bit support + IF \ IF 64 bit support + pci-next-mem-extend-1mb + 1- \ | make limit one less than boundary + pci-next-mem64 @ 100000000 #aligned \ | Reat current value of 64-bar and align at 4GB + dup pci-next-mem64 x! \ | and write it back + 1- \ | make limite one less than boundary + 2 pick swap \ | + 20 rshift \ | keep upper 32 bits + swap 2C + rtas-config-l! \ | and write it into the Limit-Upper32-bits + FFFF0000 and \ | keep upper 16 bits + over 24 + rtas-config-l@ + 0000FFFF and \ | fetch original Value + or swap 24 + rtas-config-l! \ and write it into the bridge + ELSE + \ Update current variable (add space for hot-plugging and align it) + pci-next-mem-extend-1mb + 1- \ | make limit one less than boundary + FFFF0000 and \ | keep upper 16 bits + over 24 + rtas-config-l@ + 0000FFFF and \ | fetch original Value + or swap 24 + rtas-config-l! \ | and write it into the bridge + THEN ; \ Update pci-next-io to be 4KB aligned and set the io-base and io-base-upper register