Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA720C433EF for ; Wed, 22 Sep 2021 18:19:16 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96D9060F12 for ; Wed, 22 Sep 2021 18:19:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 96D9060F12 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.193008.343787 (Exim 4.92) (envelope-from ) id 1mT6pl-0004BN-0X; Wed, 22 Sep 2021 18:19:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 193008.343787; Wed, 22 Sep 2021 18:19:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mT6pk-0004BG-TZ; Wed, 22 Sep 2021 18:19:04 +0000 Received: by outflank-mailman (input) for mailman id 193008; Wed, 22 Sep 2021 18:19:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mT6pk-0004BA-1g for xen-devel@lists.xenproject.org; Wed, 22 Sep 2021 18:19:04 +0000 Received: from mail-lf1-x12a.google.com (unknown [2a00:1450:4864:20::12a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c754cfad-bc99-4853-84a0-f393c54364a9; Wed, 22 Sep 2021 18:19:02 +0000 (UTC) Received: by mail-lf1-x12a.google.com with SMTP id y28so15381574lfb.0 for ; Wed, 22 Sep 2021 11:19:02 -0700 (PDT) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id c4sm235296lfr.59.2021.09.22.11.18.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Sep 2021 11:19:00 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c754cfad-bc99-4853-84a0-f393c54364a9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=cdYrxpSpDGHg9um55NhNlBekvRpOeiukL4q9FZQajXE=; b=VxZbTzo5LCN+0LPMsq7iMB2RnKDBOTx91/hktHfmUT2o+FVy/DDIug+jd0g8S3WTQ3 JSAwNZf861jfjtebX1b1rD9AmeI80niHcfOOR3lyFCEA97Avw32MX37wDuF5/SLeaB6U RHLl0kbOAMZlW7i9GjxpkL/jtIetxt5CJnM5I0PoL+M9tkShhHOUFyvUX3xhBpTozuzC TEClfbambtr5NcEYyaey+Yg4s5ruu2YGYAv4io4iWjnVOYkK7OjHXtr8X71WPdqMnHrC W9qH2/GaXNe4sYn6svmUMrifx/ZIfM1Rt93eCLXUrNiEu4qN3Vbs/GIojGt5/dIWgjW8 XSmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=cdYrxpSpDGHg9um55NhNlBekvRpOeiukL4q9FZQajXE=; b=GUgOUonp6OPXHUZDZudKPJxEShwKKOPCqZAt5gv9R6DQjyr9dI/cKLsJOZnG2fwlOQ sbeW0+16dYgHnmrxvIIoeuV7zymnbQi4avMnX0CSh+j5mFhgZlfd43LVj9eujhm47iDT ALqEm0bscx51cxxF0qEplnROa8PYuTi0dSzLDiZOJWcFDmHGFmD5Ou0ji3XB95fiVgl8 BerUoC+yBhbmk14f8i5p3eNht+n+1pP+SJAwuG4+INYZf9CbCrn8urMrBXz2jAOoCfEf k2pvEc+cZPP99FQ4vqnYEYkyZZOxNz1aQ48MtFMVByO+GVNpnyLfpVw7W5GzrXw4kL/s 0v1w== X-Gm-Message-State: AOAM533QfdnniTjFkYXQj3hzpyNXfdqXJGwWg5uMd55U0QzwN7Q8UM5c TA0lLnMjwkqerUJlgfKHaok= X-Google-Smtp-Source: ABdhPJxc70A3BpvdY40pWQ+iuxwUtdYUwY4Zz0aha42T6numlyxn29/up8j13uHPBX1JGalVPkNDeA== X-Received: by 2002:a05:6512:455:: with SMTP id y21mr358847lfk.548.1632334740428; Wed, 22 Sep 2021 11:19:00 -0700 (PDT) Subject: Re: [PATCH V2 2/3] xen/arm: Add handling of extended regions for Dom0 From: Oleksandr To: Stefano Stabellini Cc: Julien Grall , xen-devel@lists.xenproject.org, Oleksandr Tyshchenko , Volodymyr Babchuk , Henry Wang , Bertrand Marquis , Wei Chen References: <1631297924-8658-1-git-send-email-olekstysh@gmail.com> <1631297924-8658-3-git-send-email-olekstysh@gmail.com> <0a72559e-5742-dc33-1c8f-5903c50b27be@xen.org> <08294c53-109a-8544-3a23-85e034d2992d@gmail.com> Message-ID: Date: Wed, 22 Sep 2021 21:18:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Hi Stefano [snip] >>> >>> >>>> >>>> You will also need to cover "ranges" that will describe the BARs >>>> for the PCI >>>> devices. >>> Good point. >> Yes, very good point! >> >> >>> Could you please clarify how to recognize whether it is a PCI >>> device as long as PCI support is not merged? Or just to find any >>> device nodes >>> with non-empty "ranges" property >>> and retrieve addresses? >> Normally any bus can have a ranges property with the aperture and >> possible address translations, including /amba (compatible = >> "simple-bus"). However, in these cases dt_device_get_address already >> takes care of it, see xen/common/device_tree.c:dt_device_get_address. >> >> The PCI bus is special for 2 reasons: >> - the ranges property has a different format >> - the bus is hot-pluggable >> >> So I think the only one that we need to treat specially is PCI. >> >> As far as I am aware PCI is the only bus (or maybe just the only bus >> that we support?) where ranges means the aperture. > Thank you for the clarification. I need to find device node with > non-empty ranges property > (and make sure that device_type property is "pci"), after that I need > to read the context of ranges property and translate it. > > OK, I experimented with that and managed to parse ranges property for PCI host bridge node. I tested on my setup where the host device tree contains two PCI host bridge nodes with the following: pcie@fe000000 { ...             ranges = <0x1000000 0x0 0x0 0x0 0xfe100000 0x0 0x100000 0x2000000 0x0 0xfe200000 0x0 0xfe200000 0x0 0x200000 0x2000000 0x0 0x30000000 0x0 0x30000000 0x0 0x8000000 0x42000000 0x0 0x38000000 0x0 0x38000000 0x0 0x8000000>; ... }; pcie@ee800000 { ...             ranges = <0x1000000 0x0 0x0 0x0 0xee900000 0x0 0x100000 0x2000000 0x0 0xeea00000 0x0 0xeea00000 0x0 0x200000 0x2000000 0x0 0xc0000000 0x0 0xc0000000 0x0 0x8000000 0x42000000 0x0 0xc8000000 0x0 0xc8000000 0x0 0x8000000>; ... }; So Xen retrieves the *CPU addresses* from the ranges: (XEN) dev /soc/pcie@fe000000 range_size 7 nr_ranges 4 (XEN) 0: addr=fe100000, size=100000 (XEN) 1: addr=fe200000, size=200000 (XEN) 2: addr=30000000, size=8000000 (XEN) 3: addr=38000000, size=8000000 (XEN) dev /soc/pcie@ee800000 range_size 7 nr_ranges 4 (XEN) 0: addr=ee900000, size=100000 (XEN) 1: addr=eea00000, size=200000 (XEN) 2: addr=c0000000, size=8000000 (XEN) 3: addr=c8000000, size=8000000 The code below covers ranges property in the context of finding memory holes (to be squashed with current patch): diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d37156a..7d20c10 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -834,6 +834,8 @@ static int __init find_memory_holes(struct meminfo *ext_regions)      {          unsigned int naddr;          u64 addr, size; +        const __be32 *ranges; +        u32 len;          naddr = dt_number_of_address(np); @@ -857,6 +859,41 @@ static int __init find_memory_holes(struct meminfo *ext_regions)                  goto out;              }          } + +        /* +         * Also looking for non-empty ranges property which would likely mean +         * that we deal with PCI host bridge device and the property here +         * describes the BARs for the PCI devices. +         */ +        ranges = dt_get_property(np, "ranges", &len); +        if ( ranges && len ) +        { +            unsigned int range_size, nr_ranges; +            int na, ns, pna; + +            pna = dt_n_addr_cells(np); +            na = dt_child_n_addr_cells(np); +            ns = dt_child_n_size_cells(np); +            range_size = pna + na + ns; +            nr_ranges = len / sizeof(__be32) / range_size; + +            for ( i = 0; i < nr_ranges; i++, ranges += range_size ) +            { +                /* Skip the child address and get the parent (CPU) address */ +                addr = dt_read_number(ranges + na, pna); +                size = dt_read_number(ranges + na + pna, ns); + +                start = addr & PAGE_MASK; +                end = PAGE_ALIGN(addr + size); +                res = rangeset_remove_range(mem_holes, start, end - 1); +                if ( res ) +                { +                    printk(XENLOG_ERR "Failed to remove: %#"PRIx64"->%#"PRIx64"\n", +                           start, end); +                    goto out; +                } +            } +        }      }      start = 0; -- Regards, Oleksandr Tyshchenko