From: vijay.kilari@gmail.com Subject: [RFC PATCH v3 06/18] xen/arm: ITS: Add helper functions to manage its_devices Date: Mon, 22 Jun 2015 17:31:45 +0530 Message-ID: <1434974517-12136-7-git-send-email-vijay.kilari@gmail.com> References: <1434974517-12136-1-git-send-email-vijay.kilari@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1434974517-12136-1-git-send-email-vijay.kilari@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian.Campbell@citrix.com, julien.grall@citrix.com, stefano.stabellini@eu.citrix.com, stefano.stabellini@citrix.com, tim@xen.org, xen-devel@lists.xen.org Cc: Prasun.Kapoor@caviumnetworks.com, Vijaya Kumar K , manish.jaggi@caviumnetworks.com, vijay.kilari@gmail.com List-Id: xen-devel@lists.xenproject.org From: Vijaya Kumar K Helper functions to mange its devices using RB-tree are introduced in physical ITS driver. This is global list of all the devices. Signed-off-by: Vijaya Kumar K --- xen/arch/arm/gic-v3-its.c | 49 +++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/gic-its.h | 3 +++ 2 files changed, 52 insertions(+) diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c index b1a97c1..349d0bb 100644 --- a/xen/arch/arm/gic-v3-its.c +++ b/xen/arch/arm/gic-v3-its.c @@ -92,6 +92,7 @@ struct its_node { static LIST_HEAD(its_nodes); static DEFINE_SPINLOCK(its_lock); static struct rdist_prop *gic_rdists; +static struct rb_root rb_its_dev; #define gic_data_rdist() (per_cpu(rdist, smp_processor_id())) #define gic_data_rdist_rd_base() (per_cpu(rdist, smp_processor_id()).rbase) @@ -145,6 +146,53 @@ void dump_cmd(its_cmd_block *cmd) } #endif +/* RB-tree helpers for its_device */ +struct its_device * find_its_device(struct rb_root *root, u32 devid) +{ + struct rb_node *node = root->rb_node; + + while ( node ) + { + struct its_device *dev; + + dev = container_of(node, struct its_device, node); + if ( devid < dev->device_id ) + node = node->rb_left; + else if ( devid > dev->device_id ) + node = node->rb_right; + else + return dev; + } + + return NULL; +} + +int insert_its_device(struct rb_root *root, struct its_device *dev) +{ + struct rb_node **new, *parent; + + new = &root->rb_node; + parent = NULL; + while ( *new ) + { + struct its_device *this; + + this = container_of(*new, struct its_device, node); + parent = *new; + if ( dev->device_id < this->device_id ) + new = &((*new)->rb_left); + else if ( dev->device_id > this->device_id ) + new = &((*new)->rb_right); + else + return -EEXIST; + } + + rb_link_node(&dev->node, parent, new); + rb_insert_color(&dev->node, root); + + return 0; +} + #define ITS_CMD_QUEUE_SZ SZ_64K #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(its_cmd_block)) @@ -994,6 +1042,7 @@ static int its_probe(struct dt_device_node *node) list_add(&its->entry, &its_nodes); spin_unlock(&its_lock); + rb_its_dev = RB_ROOT; return 0; out_free_tables: diff --git a/xen/include/asm-arm/gic-its.h b/xen/include/asm-arm/gic-its.h index 4e42f7f..59a6490 100644 --- a/xen/include/asm-arm/gic-its.h +++ b/xen/include/asm-arm/gic-its.h @@ -19,6 +19,7 @@ #define __ASM_ARM_GIC_ITS_H__ #include +#include /* * Collection structure - just an ID, and a redistributor address to @@ -195,6 +196,8 @@ struct its_device { u32 nr_ites; /* Physical Device id */ u32 device_id; + /* RB-tree entry */ + struct rb_node node; }; static inline uint8_t its_decode_cmd(its_cmd_block *cmd) -- 1.7.9.5