From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: Re: [PATCH v4 04/17] xen/arm: ITS: Add helper functions to manage its_devices Date: Wed, 15 Jul 2015 12:37:00 +0200 Message-ID: <55A637CC.10003@citrix.com> References: <1436514172-3263-1-git-send-email-vijay.kilari@gmail.com> <1436514172-3263-5-git-send-email-vijay.kilari@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1436514172-3263-5-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: vijay.kilari@gmail.com, Ian.Campbell@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 List-Id: xen-devel@lists.xenproject.org Hi Vijay, On 10/07/2015 09:42, vijay.kilari@gmail.com wrote: > --- > xen/arch/arm/gic-v3-its.c | 49 +++++++++++++++++++++++++++++++++++++++++ > xen/include/asm-arm/gic-its.h | 13 +++++++++++ > 2 files changed, 62 insertions(+) > > diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c > index 60ab646..b421a6f 100644 > --- a/xen/arch/arm/gic-v3-its.c > +++ b/xen/arch/arm/gic-v3-its.c > @@ -90,6 +90,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())) > > @@ -101,6 +102,53 @@ void dump_cmd(its_cmd_block *cmd) > } > #endif > > +/* RB-tree helpers for its_device */ > +struct its_device *its_find_device(u32 devid) > +{ > + struct rb_node *node = rb_its_dev.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 its_insert_device(struct its_device *dev) > +{ > + struct rb_node **new, *parent; > + > + new = &rb_its_dev.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, &rb_its_dev); > + > + return 0; > +} > + > #define ITS_CMD_QUEUE_SZ SZ_64K > #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(its_cmd_block)) > > @@ -811,6 +859,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; NIT: missing newline here. A general question, how do you ensure any concurrent insert to the RB-tree? Is it taken care by the ITS lock and the caller? I would be ok to defer the locking for when the PCI passthrough is supported as all the ITS device are added when Xen is booted. A TODO would be worth to add. With the TODO and the answer to my questions: Reviewed-by: Julien Grall Regards, -- Julien Grall