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

[Xen-devel] [PATCH resend 04/13] acpi: arm: Copy fwnode / iommu_fwspec code from Linux 4.14



From: Manish Jaggi <mjaggi@xxxxxxxxxxxxxxxxxx>

fwnode is firmware device node object handle type definition. This can
be used either for device tree node or ACPI table node.
However in the context of this patchset it is used mainly for ACPI
nodes.

iommu_fwspec defines set of opeations associated with fwnode.

This patch does not directly imports the code files from linux,
rahter copies only the relavant parts of code required for Xen.

Signed-off-by: Manish Jaggi <manish.jaggi@xxxxxxxxxx>
---
 xen/drivers/passthrough/arm/iommu.c |  85 ++++++++++++++++++++++++
 xen/include/asm-arm/device.h        |   1 +
 xen/include/asm-arm/fwnode.h        | 128 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/fwspec.h        |  38 +++++++++++
 4 files changed, 252 insertions(+)

diff --git a/xen/drivers/passthrough/arm/iommu.c 
b/xen/drivers/passthrough/arm/iommu.c
index 95b1abb972..6e3960e4af 100644
--- a/xen/drivers/passthrough/arm/iommu.c
+++ b/xen/drivers/passthrough/arm/iommu.c
@@ -19,6 +19,8 @@
 #include <xen/iommu.h>
 #include <xen/device_tree.h>
 #include <asm/device.h>
+#include <asm/fwnode.h>
+#include <asm/fwspec.h>
 
 static const struct iommu_ops *iommu_ops;
 
@@ -73,3 +75,86 @@ int arch_iommu_populate_page_table(struct domain *d)
     /* The IOMMU shares the p2m with the CPU */
     return -ENOSYS;
 }
+
+/**
+ * fwnode_handle_put - Drop reference to a device node
+ * @fwnode: Pointer to the device node to drop the reference to.
+ *
+ * To be used when terminating device_for_each_child_node() iteration with
+ * break / return to prevent stale device node references being left behind
+ */
+void fwnode_handle_put(struct fwnode_handle *fwnode)
+{
+    fwnode_call_void_op(fwnode, put);
+}
+
+const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
+{
+    return iommu_get_ops();
+}
+
+int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+                      const struct iommu_ops *ops)
+{
+    struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+
+    if ( fwspec )
+       return ops == fwspec->ops ? 0 : -EINVAL;
+
+    fwspec = xzalloc_bytes(sizeof(*fwspec));
+    if ( !fwspec )
+        return -ENOMEM;
+#if 0
+       of_node_get(to_of_node(iommu_fwnode)); /* TODO */
+#endif
+    fwspec->iommu_fwnode = iommu_fwnode;
+    fwspec->ops = ops;
+    dev->iommu_fwspec = fwspec;
+
+    return 0;
+}
+
+void iommu_fwspec_free(struct device *dev)
+{
+   struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+
+    if ( fwspec )
+    {
+        fwnode_handle_put(fwspec->iommu_fwnode);
+        xfree(fwspec);
+        dev->iommu_fwspec = NULL;
+    }
+}
+
+int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids)
+{
+    struct iommu_fwspec *fwspec_n;
+    struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+    size_t size, size_n;
+    int i;
+
+    if ( !fwspec )
+        return -EINVAL;
+
+    size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids]);
+    size_n = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]);
+    if ( size_n > size )
+    {
+        fwspec_n = _xzalloc(size_n, sizeof(void*));
+        if ( !fwspec_n )
+             return -ENOMEM;
+
+        memcpy(fwspec_n, fwspec, size);
+        xfree(fwspec);
+        fwspec = fwspec_n;
+    }
+
+    for ( i = 0; i < num_ids; i++ )
+        fwspec->ids[fwspec->num_ids + i] = ids[i];
+
+    fwspec->num_ids += num_ids;
+    dev->iommu_fwspec = fwspec;
+
+    return 0;
+}
+
diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h
index 6734ae8efd..7f2d8d367e 100644
--- a/xen/include/asm-arm/device.h
+++ b/xen/include/asm-arm/device.h
@@ -20,6 +20,7 @@ struct device
     struct dt_device_node *of_node; /* Used by drivers imported from Linux */
 #endif
     struct dev_archdata archdata;
+    struct iommu_fwspec *iommu_fwspec;
 };
 
 typedef struct device device_t;
diff --git a/xen/include/asm-arm/fwnode.h b/xen/include/asm-arm/fwnode.h
new file mode 100644
index 0000000000..d74c7776ea
--- /dev/null
+++ b/xen/include/asm-arm/fwnode.h
@@ -0,0 +1,128 @@
+/*
+ * fwnode.h - Firmware device node object handle type definition.
+ *
+ * Copyright (C) 2015, Intel Corporation
+ * Author: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *  Xen Modifications: Manish Jaggi
+ *  Coding Style: Linux
+ */
+
+#ifndef _ASM_ARM_FWNODE_H_
+#define _ASM_ARM_FWNODE_H_
+
+#include <xen/types.h>
+
+struct fwnode_operations;
+
+struct fwnode_handle {
+       struct fwnode_handle *secondary;
+       const struct fwnode_operations *ops;
+};
+
+/**
+ * struct fwnode_endpoint - Fwnode graph endpoint
+ * @port: Port number
+ * @id: Endpoint id
+ * @local_fwnode: reference to the related fwnode
+ */
+struct fwnode_endpoint {
+       unsigned int port;
+       unsigned int id;
+       const struct fwnode_handle *local_fwnode;
+};
+
+#define NR_FWNODE_REFERENCE_ARGS       8
+
+/**
+ * struct fwnode_reference_args - Fwnode reference with additional arguments
+ * @fwnode:- A reference to the base fwnode
+ * @nargs: Number of elements in @args array
+ * @args: Integer arguments on the fwnode
+ */
+struct fwnode_reference_args {
+       struct fwnode_handle *fwnode;
+       unsigned int nargs;
+       unsigned int args[NR_FWNODE_REFERENCE_ARGS];
+};
+
+/**
+ * struct fwnode_operations - Operations for fwnode interface
+ * @get: Get a reference to an fwnode.
+ * @put: Put a reference to an fwnode.
+ * @property_present: Return true if a property is present.
+ * @property_read_integer_array: Read an array of integer properties. Return
+ *                              zero on success, a negative error code
+ *                              otherwise.
+ * @property_read_string_array: Read an array of string properties. Return zero
+ *                             on success, a negative error code otherwise.
+ * @get_parent: Return the parent of an fwnode.
+ * @get_next_child_node: Return the next child node in an iteration.
+ * @get_named_child_node: Return a child node with a given name.
+ * @get_reference_args: Return a reference pointed to by a property, with args
+ * @graph_get_next_endpoint: Return an endpoint node in an iteration.
+ * @graph_get_remote_endpoint: Return the remote endpoint node of a local
+ *                            endpoint node.
+ * @graph_get_port_parent: Return the parent node of a port node.
+ * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
+ */
+struct fwnode_operations {
+       void (*get)(struct fwnode_handle *fwnode);
+       void (*put)(struct fwnode_handle *fwnode);
+       bool (*device_is_available)(const struct fwnode_handle *fwnode);
+       bool (*property_present)(const struct fwnode_handle *fwnode,
+                                const char *propname);
+       int (*property_read_int_array)(const struct fwnode_handle *fwnode,
+                                      const char *propname,
+                                      unsigned int elem_size, void *val,
+                                      size_t nval);
+       int
+       (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
+                                     const char *propname, const char **val,
+                                     size_t nval);
+       struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
+       struct fwnode_handle *
+       (*get_next_child_node)(const struct fwnode_handle *fwnode,
+                              struct fwnode_handle *child);
+       struct fwnode_handle *
+       (*get_named_child_node)(const struct fwnode_handle *fwnode,
+                               const char *name);
+       int (*get_reference_args)(const struct fwnode_handle *fwnode,
+                                 const char *prop, const char *nargs_prop,
+                                 unsigned int nargs, unsigned int index,
+                                 struct fwnode_reference_args *args);
+       struct fwnode_handle *
+       (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
+                                  struct fwnode_handle *prev);
+       struct fwnode_handle *
+       (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
+       struct fwnode_handle *
+       (*graph_get_port_parent)(struct fwnode_handle *fwnode);
+       int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
+                                   struct fwnode_endpoint *endpoint);
+};
+
+#define fwnode_has_op(fwnode, op)                              \
+       ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
+#define fwnode_call_int_op(fwnode, op, ...)                            \
+       (fwnode ? (fwnode_has_op(fwnode, op) ?                          \
+                  (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
+        -EINVAL)
+#define fwnode_call_bool_op(fwnode, op, ...)                           \
+       (fwnode ? (fwnode_has_op(fwnode, op) ?                          \
+                  (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \
+        false)
+#define fwnode_call_ptr_op(fwnode, op, ...)            \
+       (fwnode_has_op(fwnode, op) ?                    \
+        (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
+#define fwnode_call_void_op(fwnode, op, ...)                           \
+       do {                                                            \
+               if (fwnode_has_op(fwnode, op))                          \
+                       (fwnode)->ops->op(fwnode, ## __VA_ARGS__);      \
+       } while (false)
+
+#endif
diff --git a/xen/include/asm-arm/fwspec.h b/xen/include/asm-arm/fwspec.h
new file mode 100644
index 0000000000..e67d2bb678
--- /dev/null
+++ b/xen/include/asm-arm/fwspec.h
@@ -0,0 +1,38 @@
+/*
+ *
+ * Copyright (C) 2015, Intel Corporation
+ * Author: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *  Xen Modifications: Manish Jaggi
+ */
+
+#ifndef _ASM_FWSPEC_H
+#define _ASM_FWSPEC_H
+
+/**
+ * struct iommu_fwspec - per-device IOMMU instance data
+ * @ops: ops for this device's IOMMU
+ * @iommu_fwnode: firmware handle for this device's IOMMU
+ * @iommu_priv: IOMMU driver private data for this device
+ * @num_ids: number of associated device IDs
+ * @ids: IDs which this device may present to the IOMMU
+ */
+struct iommu_fwspec {
+        const struct iommu_ops  *ops;
+        struct fwnode_handle    *iommu_fwnode;
+        void                    *iommu_priv;
+        unsigned int            num_ids;
+        u32                     ids[1];
+};
+
+int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+                      const struct iommu_ops *ops);
+void iommu_fwspec_free(struct device *dev);
+int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
+const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode);
+
+#endif
-- 
2.14.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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