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=-4.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 08733C433F5 for ; Tue, 21 Sep 2021 19:43:35 +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 ABFB660EC0 for ; Tue, 21 Sep 2021 19:43:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ABFB660EC0 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.191875.342016 (Exim 4.92) (envelope-from ) id 1mSlfb-0000b9-DM; Tue, 21 Sep 2021 19:43:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 191875.342016; Tue, 21 Sep 2021 19:43:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSlfb-0000b2-Aa; Tue, 21 Sep 2021 19:43:11 +0000 Received: by outflank-mailman (input) for mailman id 191875; Tue, 21 Sep 2021 19:43:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSlfa-0000ad-4U for xen-devel@lists.xenproject.org; Tue, 21 Sep 2021 19:43:10 +0000 Received: from mail-lf1-x12b.google.com (unknown [2a00:1450:4864:20::12b]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6c28d9ec-10e7-4e97-a77b-7bb88d92e38c; Tue, 21 Sep 2021 19:43:08 +0000 (UTC) Received: by mail-lf1-x12b.google.com with SMTP id y28so2287016lfb.0 for ; Tue, 21 Sep 2021 12:43:08 -0700 (PDT) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id y32sm1589020lfa.171.2021.09.21.12.43.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 12:43:07 -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: 6c28d9ec-10e7-4e97-a77b-7bb88d92e38c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=Gn/9MMD+lIm5s/bvzqWXUO99oDTImbcpJ6nNxz3pWUY=; b=IYvy+pKq+jVPWuXihjEuNNhU5SUrrLxqfECkYSBvQC43m4XNm+3IzLGBopysvAODen iGhnpOVKc4AaW1lias53UuPcm0HqB4eliYJrL9y0bw8lhAvttkUBsWB33OJjUhphteRy e+j4AluLf8tnlGU+Ikp5LOuCRWMybzYEUBrT4nu6UGWLU10iBVh86Ox+keZW//F5yDQo j0qYa/TPnGljHITZLfDy1VBWIpn/wlrs2u21FX+PUkwkuM+BZgNaDyxBeO9qU+18Q51e OEG9x+VG4iZKcrD2Wc9YN6iboGXoKrfWjKQXtP2MrFgU2pGNUNgnsa3dQdSozlMYffBf rbDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Gn/9MMD+lIm5s/bvzqWXUO99oDTImbcpJ6nNxz3pWUY=; b=66uHOh8Sl5QKreX2+Bud0/DRhBvJuQ0lybGiHIe+s9P2OKqvMzKMZGW2A74ZRZnR0b lvRiU8/36CHfiSgWMcisw8Wq/Fqcp6koMJx/0+2d4XgtktpnuMH5zs+mSCFEJ9W5zksY aeLRTlG7/nz4BOY9KDtP3Q7yx0u2w7QBC3M7ASTyapVIJ8bqFdLNncasI7PdTVFgn+Z6 2zz+8Hp46fApdv1rR2Lkgnrpmt4YN3j+fBrn3u5fcMovJfOc/f1NPGXjKc7L/sbkY5f4 qVnbHeA8GItRH2rOAbf6a73zQjcy4kHoeo2WfUMDy7vzxRt/BGHz6ryYCENYcLooCMJC XsSw== X-Gm-Message-State: AOAM531IBSjPZ4iZJwCvQ0v8hlfcdh4mzFrLQiRVY4tgbxExwr1taj7+ OWkdg263iA2I3iIGUeFBo28= X-Google-Smtp-Source: ABdhPJxo8Dzr7HhmpYwOAWh4FSnBDNUC2xpiyznNVZBRDzUoTO4oAK3+K0qwB9R/pkwEJYca1w0kUg== X-Received: by 2002:a2e:2a06:: with SMTP id q6mr28912275ljq.424.1632253387596; Tue, 21 Sep 2021 12:43:07 -0700 (PDT) Subject: Re: [PATCH V2 2/3] xen/arm: Add handling of extended regions for Dom0 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> From: Oleksandr Message-ID: Date: Tue, 21 Sep 2021 22:43:06 +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 On 18.09.21 00:56, Stefano Stabellini wrote: Hi Stefano > On Fri, 17 Sep 2021, Oleksandr wrote: >>>> + >>>> +    dt_dprintk("Find unallocated memory for extended regions\n"); >>>> + >>>> +    unalloc_mem = rangeset_new(NULL, NULL, 0); >>>> +    if ( !unalloc_mem ) >>>> +        return -ENOMEM; >>>> + >>>> +    /* Start with all available RAM */ >>>> +    for ( i = 0; i < bootinfo.mem.nr_banks; i++ ) >>>> +    { >>>> +        start = bootinfo.mem.bank[i].start; >>>> +        end = bootinfo.mem.bank[i].start + bootinfo.mem.bank[i].size - 1; >>>> +        res = rangeset_add_range(unalloc_mem, start, end); >>>> +        if ( res ) >>>> +        { >>>> +            printk(XENLOG_ERR "Failed to add: %#"PRIx64"->%#"PRIx64"\n", >>>> +                   start, end); >>>> +            goto out; >>>> +        } >>>> +    } >>>> + >>>> +    /* Remove RAM assigned to Dom0 */ >>>> +    for ( i = 0; i < assign_mem->nr_banks; i++ ) >>>> +    { >>>> +        start = assign_mem->bank[i].start; >>>> +        end = assign_mem->bank[i].start + assign_mem->bank[i].size - 1; >>>> +        res = rangeset_remove_range(unalloc_mem, start, end); >>>> +        if ( res ) >>>> +        { >>>> +            printk(XENLOG_ERR "Failed to remove: >>>> %#"PRIx64"->%#"PRIx64"\n", >>>> +                   start, end); >>>> +            goto out; >>>> +        } >>>> +    } >>>> + >>>> +    /* Remove reserved-memory regions */ >>>> +    for ( i = 0; i < bootinfo.reserved_mem.nr_banks; i++ ) >>>> +    { >>>> +        start = bootinfo.reserved_mem.bank[i].start; >>>> +        end = bootinfo.reserved_mem.bank[i].start + >>>> +            bootinfo.reserved_mem.bank[i].size - 1; >>>> +        res = rangeset_remove_range(unalloc_mem, start, end); >>>> +        if ( res ) >>>> +        { >>>> +            printk(XENLOG_ERR "Failed to remove: >>>> %#"PRIx64"->%#"PRIx64"\n", >>>> +                   start, end); >>>> +            goto out; >>>> +        } >>>> +    } >>>> + >>>> +    /* Remove grant table region */ >>>> +    start = kinfo->gnttab_start; >>>> +    end = kinfo->gnttab_start + kinfo->gnttab_size - 1; >>>> +    res = rangeset_remove_range(unalloc_mem, start, end); >>>> +    if ( res ) >>>> +    { >>>> +        printk(XENLOG_ERR "Failed to remove: %#"PRIx64"->%#"PRIx64"\n", >>>> +               start, end); >>>> +        goto out; >>>> +    } >>>> + >>>> +    start = EXT_REGION_START; >>>> +    end = min((1ULL << p2m_ipa_bits) - 1, EXT_REGION_END); >>>> +    res = rangeset_report_ranges(unalloc_mem, start, end, >>>> +                                 add_ext_regions, ext_regions); >>>> +    if ( res ) >>>> +        ext_regions->nr_banks = 0; >>>> +    else if ( !ext_regions->nr_banks ) >>>> +        res = -ENOENT; >>>> + >>>> +out: >>>> +    rangeset_destroy(unalloc_mem); >>>> + >>>> +    return res; >>>> +} >>>> + >>>> +static int __init find_memory_holes(const struct kernel_info *kinfo, >>>> +                                    struct meminfo *ext_regions) >>>> +{ >>>> +    struct dt_device_node *np; >>>> +    struct rangeset *mem_holes; >>>> +    paddr_t start, end; >>>> +    unsigned int i; >>>> +    int res; >>>> + >>>> +    dt_dprintk("Find memory holes for extended regions\n"); >>>> + >>>> +    mem_holes = rangeset_new(NULL, NULL, 0); >>>> +    if ( !mem_holes ) >>>> +        return -ENOMEM; >>>> + >>>> +    /* Start with maximum possible addressable physical memory range */ >>>> +    start = EXT_REGION_START; >>>> +    end = min((1ULL << p2m_ipa_bits) - 1, EXT_REGION_END); >>>> +    res = rangeset_add_range(mem_holes, start, end); >>>> +    if ( res ) >>>> +    { >>>> +        printk(XENLOG_ERR "Failed to add: %#"PRIx64"->%#"PRIx64"\n", >>>> +               start, end); >>>> +        goto out; >>>> +    } >>>> + >>>> +    /* Remove all regions described by "reg" property (MMIO, RAM, etc) */ >>> Well... The loop below is not going to handle all the regions described in >>> the property "reg". Instead, it will cover a subset of "reg" where the >>> memory is addressable. >> As I understand, we are only interested in subset of "reg" where the memory is >> addressable. >> >> >>> >>> 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. -- Regards, Oleksandr Tyshchenko