From patchwork Wed Aug 22 12:30:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 179366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BA6DB2C0080 for ; Thu, 23 Aug 2012 04:55:00 +1000 (EST) Received: from localhost ([::1]:38552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G4w-0001a5-Td for incoming@patchwork.ozlabs.org; Wed, 22 Aug 2012 14:54:58 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G4D-0008IF-Jp for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:54:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4G4C-0006mb-MY for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:54:13 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:64243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G4C-0006lT-Bn for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:54:12 -0400 X-IronPort-AV: E=Sophos;i="4.80,809,1344225600"; d="scan'208";a="205942910" Received: from ftlpmailmx01.citrite.net ([10.13.107.65]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 22 Aug 2012 14:54:04 -0400 Received: from meteora.cam.xci-test.com (10.80.248.22) by smtprelay.citrix.com (10.13.107.65) with Microsoft SMTP Server id 8.3.213.0; Wed, 22 Aug 2012 14:54:04 -0400 From: Julien Grall To: qemu-devel@nongnu.org Date: Wed, 22 Aug 2012 13:30:17 +0100 Message-ID: <218c6f257e81ec8ae998002f6ec6669002453d6a.1345637459.git.julien.grall@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Julien Grall , christian.limpach@gmail.com, Stefano.Stabellini@eu.citrix.com, xen-devel@lists.xen.org Subject: [Qemu-devel] [QEMU][RFC V2 04/10] xen-hvm: register qemu as ioreq server and retrieve shared pages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org With QEMU disaggregation in Xen environment, each QEMU needs to ask Xen for an ioreq server id. This id will be use to retrieve its private share pages. Signed-off-by: Julien Grall --- xen-all.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 76 insertions(+), 4 deletions(-) diff --git a/xen-all.c b/xen-all.c index df6927d..5f05838 100644 --- a/xen-all.c +++ b/xen-all.c @@ -36,6 +36,7 @@ static MemoryRegion ram_memory, ram_640k, ram_lo, ram_hi; static MemoryRegion *framebuffer; +static unsigned int serverid; static uint32_t xen_dmid = ~0; /* Compatibility with older version */ @@ -64,6 +65,67 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) #define HVM_PARAM_BUFIOREQ_EVTCHN 26 #endif +#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00040300 +static inline unsigned long xen_buffered_iopage(void) +{ + unsigned long pfn; + + xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_BUFIOREQ_PFN, &pfn); + + return pfn; +} + +static inline unsigned long xen_iopage(void) +{ + unsigned long pfn; + + xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IOREQ_PFN, &pfn); + + return pfn; +} + +static inline evtchn_port_or_error_t xen_buffered_channel(void) +{ + unsigned long evtchn; + int rc; + + rc = xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_BUFIOREQ_EVTCHN, + &evtchn); + + if (rc < 0) { + return rc; + } else { + return evtchn; + } +} +#else +static inline unsigned long xen_buffered_iopage(void) +{ + unsigned long pfn; + + xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IO_PFN_FIRST, &pfn); + pfn += (serverid - 1) * 2 + 2; + + return pfn; +} + +static inline unsigned long xen_iopage(void) +{ + unsigned long pfn; + + xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IO_PFN_FIRST, &pfn); + pfn += (serverid - 1) * 2 + 1; + + return pfn; +} + +static inline evtchn_port_or_error_t xen_buffered_channel(void) +{ + return xc_hvm_get_ioreq_server_buf_channel(xen_xc, xen_domid, serverid); +} + +#endif + #define BUFFER_IO_MAX_DELAY 100 typedef struct XenPhysmap { @@ -1112,7 +1174,15 @@ int xen_hvm_init(void) state->suspend.notify = xen_suspend_notifier; qemu_register_suspend_notifier(&state->suspend); - xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn); + rc = xen_xc_hvm_register_ioreq_server(xen_xc, xen_domid); + + if (rc < 0) { + hw_error("registered server returned error %d", rc); + } + + serverid = rc; + + ioreq_pfn = xen_iopage(); DPRINTF("shared page at pfn %lx\n", ioreq_pfn); state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE, PROT_READ|PROT_WRITE, ioreq_pfn); @@ -1121,7 +1191,7 @@ int xen_hvm_init(void) errno, xen_xc); } - xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_BUFIOREQ_PFN, &ioreq_pfn); + ioreq_pfn = xen_buffered_iopage(); DPRINTF("buffered io page at pfn %lx\n", ioreq_pfn); state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE, PROT_READ|PROT_WRITE, ioreq_pfn); @@ -1142,12 +1212,14 @@ int xen_hvm_init(void) state->ioreq_local_port[i] = rc; } - rc = xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_BUFIOREQ_EVTCHN, - &bufioreq_evtchn); + rc = xen_buffered_channel(); if (rc < 0) { fprintf(stderr, "failed to get HVM_PARAM_BUFIOREQ_EVTCHN\n"); return -1; } + + bufioreq_evtchn = rc; + rc = xc_evtchn_bind_interdomain(state->xce_handle, xen_domid, (uint32_t)bufioreq_evtchn); if (rc == -1) {