diff mbox

[Xen-devel,v3,7/8] xen/device_tree: Add dt_device_get_address_raw

Message ID 1415180475-8339-8-git-send-email-frediano.ziglio@huawei.com
State New
Headers show

Commit Message

Frediano Ziglio Nov. 5, 2014, 9:41 a.m. UTC
Allow to read untranslated address from device node.

Signed-off-by: Frediano Ziglio <frediano.ziglio@huawei.com>
---
 xen/common/device_tree.c      | 34 ++++++++++++++++++++++++++++++++++
 xen/include/xen/device_tree.h | 11 +++++++++++
 2 files changed, 45 insertions(+)

Comments

Julien Grall Nov. 5, 2014, 2:18 p.m. UTC | #1
Hi Frediano,

I will made a global comment here for patch #7 and #8.

On 11/05/2014 09:41 AM, Frediano Ziglio wrote:
> Allow to read untranslated address from device node.
> 
> Signed-off-by: Frediano Ziglio <frediano.ziglio@huawei.com>
> ---
>  xen/common/device_tree.c      | 34 ++++++++++++++++++++++++++++++++++
>  xen/include/xen/device_tree.h | 11 +++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index 1a886c0..4186a24 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -711,6 +711,40 @@ int dt_device_get_address(const struct dt_device_node *dev, int index,
>      return 0;
>  }
>  
> +/* dt_device_get_address_raw - Returns address not translated */
> +int dt_device_get_address_raw(const struct dt_device_node *dev, int index,
> +                          u64 *addr)

This is wrong to assume that the untranslated address will fit in a 64
bits value.

Technically an untranslated address could be encoded on up to 4 cells
(though it has been hardcoded).

In any case, I don't think this is the right solution to the problem. As
DOM0 will always have the same layout as the hardware for the GIC, we
should copy "regs" and strip the unecessary regions (such as the GICH
and GICV).

Regards,
diff mbox

Patch

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 1a886c0..4186a24 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -711,6 +711,40 @@  int dt_device_get_address(const struct dt_device_node *dev, int index,
     return 0;
 }
 
+/* dt_device_get_address_raw - Returns address not translated */
+int dt_device_get_address_raw(const struct dt_device_node *dev, int index,
+                          u64 *addr)
+{
+    const __be32 *addrp;
+    const struct dt_device_node *parent;
+    const struct dt_bus *bus;
+    int na, ns;
+
+    if ( !addr )
+        return -EINVAL;
+
+    addrp = dt_get_address(dev, index, NULL, NULL);
+    if ( addrp == NULL )
+        return -EINVAL;
+
+    /* Get parent & match bus type */
+    parent = dt_get_parent(dev);
+    if ( parent == NULL )
+        return -EINVAL;
+    bus = dt_match_bus(parent);
+    if ( !bus )
+        return -EINVAL;
+
+    /* Count address cells & copy address locally */
+    bus->count_cells(dev, &na, &ns);
+    if ( !DT_CHECK_ADDR_COUNT(na) )
+        return -EINVAL;
+
+    *addr = dt_read_number(addrp, na);
+    return 0;
+}
+
+
 /**
  * dt_find_node_by_phandle - Find a node given a phandle
  * @handle: phandle of the node to find
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 629bfb2..3d2a4ae 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -475,6 +475,17 @@  int dt_device_get_address(const struct dt_device_node *dev, int index,
                           u64 *addr, u64 *size);
 
 /**
+ * dt_device_get_address_raw - Get 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
+ *
+ * This function get a raw (unresolved) address. It returns 0 on success.
+ */
+int dt_device_get_address_raw(const struct dt_device_node *dev, int index,
+                          u64 *addr);
+
+/**
  * dt_number_of_irq - Get the number of IRQ for a device
  * @device: the device whose number of interrupt is to be retrieved
  *