From owner-svn-src-all@freebsd.org Thu Apr 7 07:12:59 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 20759B065EC; Thu, 7 Apr 2016 07:12:59 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F12E815B8; Thu, 7 Apr 2016 07:12:58 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u377Cwlf071686; Thu, 7 Apr 2016 07:12:58 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u377CwAk071684; Thu, 7 Apr 2016 07:12:58 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201604070712.u377CwAk071684@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 7 Apr 2016 07:12:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297641 - head/sys/dev/hyperv/vmbus X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2016 07:12:59 -0000 Author: sephe Date: Thu Apr 7 07:12:57 2016 New Revision: 297641 URL: https://svnweb.freebsd.org/changeset/base/297641 Log: hyperv: Use lapic_{alloc,free}_ipi to allocate private interrupt vector Suggested by: jhb Reviewed by: Dexuan Cui , Jun Su Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5850 Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Apr 7 07:12:14 2016 (r297640) +++ head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Apr 7 07:12:57 2016 (r297641) @@ -391,80 +391,9 @@ vmbus_probe(device_t dev) { } #ifdef HYPERV -extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback); - -/** - * @brief Find a free IDT slot and setup the interrupt handler. - */ -static int -vmbus_vector_alloc(void) -{ - int vector; - uintptr_t func; - struct gate_descriptor *ip; - - /* - * Search backwards form the highest IDT vector available for use - * as vmbus channel callback vector. We install 'hv_vmbus_callback' - * handler at that vector and use it to interrupt vcpus. - */ - vector = APIC_SPURIOUS_INT; - while (--vector >= APIC_IPI_INTS) { - ip = &idt[vector]; - func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); - if (func == (uintptr_t)&IDTVEC(rsvd)) { -#ifdef __i386__ - setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYS386IGT, - SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); -#else - setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYSIGT, - SEL_KPL, 0); +extern inthand_t IDTVEC(hv_vmbus_callback); #endif - return (vector); - } - } - return (0); -} - -/** - * @brief Restore the IDT slot to rsvd. - */ -static void -vmbus_vector_free(int vector) -{ - uintptr_t func; - struct gate_descriptor *ip; - - if (vector == 0) - return; - - KASSERT(vector >= APIC_IPI_INTS && vector < APIC_SPURIOUS_INT, - ("invalid vector %d", vector)); - - ip = &idt[vector]; - func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); - KASSERT(func == (uintptr_t)&IDTVEC(hv_vmbus_callback), - ("invalid vector %d", vector)); - - setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0); -} - -#else /* HYPERV */ - -static int -vmbus_vector_alloc(void) -{ - return(0); -} - -static void -vmbus_vector_free(int vector) -{ -} - -#endif /* HYPERV */ - /** * @brief Main vmbus driver initialization routine. * @@ -497,12 +426,15 @@ vmbus_bus_init(void) return (ret); } +#ifdef HYPERV /* * Find a free IDT slot for vmbus callback. */ - hv_vmbus_g_context.hv_cb_vector = vmbus_vector_alloc(); - - if (hv_vmbus_g_context.hv_cb_vector == 0) { + hv_vmbus_g_context.hv_cb_vector = lapic_ipi_alloc(IDTVEC(hv_vmbus_callback)); +#else + hv_vmbus_g_context.hv_cb_vector = -1; +#endif + if (hv_vmbus_g_context.hv_cb_vector < 0) { if(bootverbose) printf("Error VMBUS: Cannot find free IDT slot for " "vmbus callback!\n"); @@ -595,7 +527,7 @@ vmbus_bus_init(void) } } - vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector); + lapic_ipi_free(hv_vmbus_g_context.hv_cb_vector); cleanup: hv_vmbus_cleanup(); @@ -663,7 +595,7 @@ vmbus_bus_exit(void) } } - vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector); + lapic_ipi_free(hv_vmbus_g_context.hv_cb_vector); return; } Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Apr 7 07:12:14 2016 (r297640) +++ head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Apr 7 07:12:57 2016 (r297641) @@ -208,10 +208,10 @@ typedef struct { struct taskqueue *hv_msg_tq[MAXCPU]; struct task hv_msg_task[MAXCPU]; /* - * Host use this vector to intrrupt guest for vmbus channel + * Host use this vector to interrupt guest for vmbus channel * event and msg. */ - unsigned int hv_cb_vector; + int hv_cb_vector; } hv_vmbus_context; /*