[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN v6 03/12] xen/arm: Introduce a wrapper for dt_device_get_address() to handle paddr_t


  • To: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Thu, 4 May 2023 09:30:00 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lX6B3Pv3MVT8M+7HUeJq5+tI69DxXdfq+5n4o6/+Vt8=; b=gj43ETfFIwHvlSYgybRFHVrOXotPzPm7IF8tKPevEzzB3z8ohM82kdPkxvMydzv48qQaRpSwb4HZrIqmwNSZmV71IsfW1C5KVOgJofrrDUCjr4FdHRjTuJImf3vn3Rpt0fZxVPh+8Dm8jIJZQ0b344OmVH1hojyRcizAA3fAeWqZPP5LjYkHmSUm94JlQHYGgzd5Uv8kvGGXx0D+Bsp9dSgiZTDEVDGHRAMdu2lg46fgDy6MB/bhiP78CE04garUl1zUEdnvwxLzgs0yywnLFbrw4HFHTfZo86DJqXwl67Y6PG9/6YdhHf16lCfnnz5A7FaVzGq5yTQGM/nTcVZ3Ug==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EV6gYA28E9DOfBjQk9A0XhceyM2C/8+TklkE1RLM354c9oyu/RYyEu9dp2epeIk/bMb2QzqGdQO7S6q4PCa25RP4IA6aQAUI7M4aZdMwrtFmF8FVDy9Nnm7nWarIYAcnpsIC5Wp9u9GQFupmxG8Yv15tKSLT2Rcdz/g4EsgQ6735/AghMkHQyq2kO1/WAGN7fd8YfmRHFCZoPaPZ+TekOSha3pNGXN17CPYj8bPRLiTjjC+UmBws0Vlq/NdvLYF45MtMVx/DFhQZP7tMVqGQ2n9lMS4F2C1FIiIBKuH23sQgvvL7+V/7IAoS8aA+YyzwrAVuXyxsA1zslkuJeg+6DA==
  • Cc: <sstabellini@xxxxxxxxxx>, <stefano.stabellini@xxxxxxx>, <julien@xxxxxxx>, <Volodymyr_Babchuk@xxxxxxxx>, <bertrand.marquis@xxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <george.dunlap@xxxxxxxxxx>, <jbeulich@xxxxxxxx>, <wl@xxxxxxx>, <rahul.singh@xxxxxxx>
  • Delivery-date: Thu, 04 May 2023 07:30:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 28/04/2023 19:55, Ayan Kumar Halder wrote:
> 
> 
> dt_device_get_address() can accept uint64_t only for address and size.
> However, the address/size denotes physical addresses. Thus, they should
> be represented by 'paddr_t'.
> Consequently, we introduce a wrapper for dt_device_get_address() ie
> dt_device_get_paddr() which accepts address/size as paddr_t and inturn
> invokes dt_device_get_address() after converting address/size to
> uint64_t.
> 
> The reason for introducing this is that in future 'paddr_t' may not
> always be 64-bit. Thus, we need an explicit wrapper to do the type
> conversion and return an error in case of truncation.
> 
> With this, callers can now invoke dt_device_get_paddr().
> 
> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index 6c9712ab7b..2163cf26d0 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -955,6 +955,45 @@ int dt_device_get_address(const struct dt_device_node 
> *dev, unsigned int index,
>      return 0;
>  }
> 
> +int dt_device_get_paddr(const struct dt_device_node *dev, unsigned int index,
> +                        paddr_t *addr, paddr_t *size)
> +{
> +    uint64_t dt_addr, dt_size;
> +    int ret;
> +
> +    ret = dt_device_get_address(dev, index, &dt_addr, &dt_size);
> +    if ( ret )
> +        return ret;
> +
> +    if ( !addr )
Because of this ...

> +        return -EINVAL;
> +
> +    if ( addr )
you should drop this.

> +    {
> +        if ( dt_addr != (paddr_t)dt_addr )
> +        {
> +            printk("Error: Physical address 0x%"PRIx64" for node=%s is 
> greater than max width (%zu bytes) supported\n",
> +                   dt_addr, dev->name, sizeof(paddr_t));
> +            return -ERANGE;
> +        }
> +
> +        *addr = dt_addr;
> +    }
> +
> +    if ( size )
> +    {
> +        if ( dt_size != (paddr_t)dt_size )
> +        {
> +            printk("Error: Physical size 0x%"PRIx64" for node=%s is greater 
> than max width (%zu bytes) supported\n",
> +                   dt_size, dev->name, sizeof(paddr_t));
> +            return -ERANGE;
> +        }
> +
> +        *size = dt_size;
> +    }
> +
> +    return ret;
> +}
> 
>  int dt_for_each_range(const struct dt_device_node *dev,
>                        int (*cb)(const struct dt_device_node *,
> diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
> index 5f8f61aec8..ce25b89c4b 100644
> --- a/xen/include/xen/device_tree.h
> +++ b/xen/include/xen/device_tree.h
> @@ -585,6 +585,19 @@ int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, 
> uint32_t u_plen,
>   */
>  const struct dt_device_node *dt_get_parent(const struct dt_device_node 
> *node);
> 
> +/**
> + * dt_device_get_paddr - Resolve an address for a device
> + * @device: the device whose address is to be resolved
> + * @index: index of the address to resolve
> + * @addr: address filled by this function
> + * @size: size filled by this function
> + *
> + * This function resolves an address, walking the tree, for a give
s/give/given

Other than that:
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

~Michal



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.