From patchwork Tue Feb 21 11:26:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 94263 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp396544qgi; Tue, 21 Feb 2017 03:28:29 -0800 (PST) X-Received: by 10.36.60.198 with SMTP id m189mr26037175ita.117.1487676509774; Tue, 21 Feb 2017 03:28:29 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a22si10926543itb.97.2017.02.21.03.28.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 03:28:29 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cg8ai-0002yX-QO; Tue, 21 Feb 2017 11:26:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cg8ah-0002wm-4N for xen-devel@lists.xenproject.org; Tue, 21 Feb 2017 11:26:43 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 77/CC-23940-2F32CA85; Tue, 21 Feb 2017 11:26:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsXiVRtsovtReU2 EwcHd8hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8afN+/YCg4YVXRc6GdtYLyl2cXIxSEkMJNR YtPdG8xdjJwcLALzmCWWd4SAJCQE+lklVrT0sIEkJARiJDqPvYKyKyS2NjQwgdhCAloSR0/NZ oWY1Mok0b9/JtAkDg42AROJWR0SIDUiAkoS91ZNBqtnFgiV+PesjR3EFgaa8+DvC1aIxaoSR8 /cBDuCV8BH4vSbkywQu+Qkbp7rBItzAsX/7nvJDrHXW2LanRVsExgFFjAyrGLUKE4tKkst0jU 010sqykzPKMlNzMzRNTQw1stNLS5OTE/NSUwq1kvOz93ECAwsBiDYwfjytOchRkkOJiVR3myp NRFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHjnKAHlBItS01Mr0jJzgCEOk5bg4FES4T2iCJTmL S5IzC3OTIdInWI05jh14/RLJo5duy6/ZBJiycvPS5US5y0DmSQAUppRmgc3CBZ7lxhlpYR5GY FOE+IpSC3KzSxBlX/FKM7BqCTMux9kCk9mXgncvldApzABnXLTYyXIKSWJCCmpBsbCST9z8r6 ZvtPna7aoWh6jXLT3KM+rXweD/P+7crNGZhueTnh+T0i4RyhBdpHhD/XNX+JieE629/iuWifu WWE6M/ZwM5v+tDUnNgcqzeb6+t/1aMeFiH0G8z0Wbo9LFHldc/2miZ7pYfWXb1Lf3orzDMzwU VoipaUwl4+n2DGiJLnl6F6tWCWW4oxEQy3mouJEAPJ/W824AgAA X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-14.tower-31.messagelabs.com!1487676399!86652296!1 X-Originating-IP: [74.125.83.52] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37964 invoked from network); 21 Feb 2017 11:26:41 -0000 Received: from mail-pg0-f52.google.com (HELO mail-pg0-f52.google.com) (74.125.83.52) by server-14.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 21 Feb 2017 11:26:41 -0000 Received: by mail-pg0-f52.google.com with SMTP id a123so33309351pgc.0 for ; Tue, 21 Feb 2017 03:26:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aAlHYLGHl/8fGXWgMpZjzzPz3Pfe9VR3h7jM6DVLEqA=; b=gw+e9LkpSLjljtcxZpQg1ZLUfh7dUSi8dXtnzGDU6J/iCkr33AFk2tRA7/jxhFpG8L WO52H4veiyiNMCqIY38crWa8gKti2zTdSGq1S2s0vchKxAlaz00Q29yfskpj869h26g2 UBbF8wFR9we/FGZXBvx10JpYWpoA53aWn4k/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aAlHYLGHl/8fGXWgMpZjzzPz3Pfe9VR3h7jM6DVLEqA=; b=tCnhL2O/s4TKPzYqAsFRgZgMaB2JsI6HHSA5E4q9czeoozvitevewLH0O2oHLEPqsp W+AWkTELBjv0ajZkTQW4HBpn8dtOMkVHpp+3qg2cUo3HGT2/PSXrKbh28FTGWPNQIJEV STQMksQ8Y8SrWucU8lKkBX+puJShP4J9VgOakZaxK5UsuGOSgs7bF3jdNmafxfvQ3Ep8 4DJEV4aDp4Y0QjZfKeszNXgJPLENqn5wzq/rlvO9cD20+Kr3rxu8dzaP0MSt3umgaaGJ YU9bqFsfOm3tyU8hkJYMOIxoVDY2q2RmxWaZNDiR5ESWGtbiCPV9hyJ6SyJzZvzJxtg+ xSRA== X-Gm-Message-State: AMke39laFE6A2bSzU/xtyy0EjuiGWc8QxPXcKolOslwVzlVBTtGWSHmno+CEzCpQp93Lf/Q0 X-Received: by 10.98.75.16 with SMTP id y16mr32596850pfa.23.1487676399273; Tue, 21 Feb 2017 03:26:39 -0800 (PST) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.18]) by smtp.gmail.com with ESMTPSA id p66sm40508627pfb.88.2017.02.21.03.26.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Feb 2017 03:26:38 -0800 (PST) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Tue, 21 Feb 2017 16:56:06 +0530 Message-Id: <1487676368-22356-10-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487676368-22356-1-git-send-email-bhupinder.thakur@linaro.org> References: <1487676368-22356-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 09/11] xen/arm: vpl011: Modify domain_create_ring in xenconsole to map the ring buffer and event channel X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Modfication in domain_create_ring(): - Bind to the vpl011 event channel obtained from the xen store as a new parameter - Map the PFN to its address space to be used as IN/OUT ring buffers. It obtains the PFN from the xen store as a new parameter Signed-off-by: Bhupinder Thakur --- tools/console/daemon/io.c | 128 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 110 insertions(+), 18 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 7e6a886..b1aa615 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -101,13 +101,18 @@ struct domain { struct domain *next; char *conspath; int ring_ref; + int vpl011_ring_ref; xenevtchn_port_or_error_t local_port; xenevtchn_port_or_error_t remote_port; + xenevtchn_port_or_error_t vpl011_local_port; + xenevtchn_port_or_error_t vpl011_remote_port; xenevtchn_handle *xce_handle; int xce_pollfd_idx; struct xencons_interface *interface; + struct xencons_interface *vpl011_interface; int event_count; long long next_period; + bool vpl011_initialized; }; static struct domain *dom_head; @@ -529,9 +534,58 @@ static void domain_unmap_interface(struct domain *dom) dom->ring_ref = -1; } +static void domain_unmap_vpl011_interface(struct domain *dom) +{ + if ( dom->vpl011_interface == NULL ) + return; + + if ( xgt_handle && dom->vpl011_ring_ref == -1 ) + xengnttab_unmap(xgt_handle, dom->vpl011_interface, 1); + else + munmap(dom->vpl011_interface, XC_PAGE_SIZE); + dom->vpl011_interface = NULL; + dom->vpl011_ring_ref = -1; +} + +int bind_event_channel(struct domain *dom, int new_rport, int *lport, int *rport) +{ + int err = 0, rc; + + /* Go no further if port has not changed and we are still bound. */ + if ( new_rport == *rport ) { + xc_evtchn_status_t status = { + .dom = DOMID_SELF, + .port = *lport }; + if ((xc_evtchn_status(xc, &status) == 0) && + (status.status == EVTCHNSTAT_interdomain)) + goto out; + } + + /* initialize the ports */ + *lport = -1; + *rport = -1; + + /* bind to new remote port */ + rc = xenevtchn_bind_interdomain(dom->xce_handle, + dom->domid, new_rport); + + if ( rc == -1 ) { + err = errno; + xenevtchn_close(dom->xce_handle); + dom->xce_handle = NULL; + goto out; + } + + /* store new local and remote event channel ports */ + *lport = rc; + *rport = new_rport; +out: + return err; +} + static int domain_create_ring(struct domain *dom) { - int err, remote_port, ring_ref, rc; + int err, remote_port, ring_ref, vpl011_remote_port, vpl011_ring_ref; char *type, path[PATH_MAX]; err = xs_gather(xs, dom->conspath, @@ -541,6 +595,20 @@ static int domain_create_ring(struct domain *dom) if (err) goto out; + /* + * if the vpl011 parameters are not available or are not initialized + * the vpl011 console is not available + */ + err = xs_gather(xs, dom->conspath, + "vpl011-ring-ref", "%u", &vpl011_ring_ref, + "vpl011-port", "%i", &vpl011_remote_port, + NULL); + + if ( err || vpl011_ring_ref == -1 ) + dom->vpl011_initialized = false; + else + dom->vpl011_initialized = true; + snprintf(path, sizeof(path), "%s/type", dom->conspath); type = xs_read(xs, XBT_NULL, path, NULL); if (type && strcmp(type, "xenconsoled") != 0) { @@ -553,6 +621,12 @@ static int domain_create_ring(struct domain *dom) if (ring_ref != dom->ring_ref && dom->ring_ref != -1) domain_unmap_interface(dom); + /* If using vpl011 ring_ref and it has changed, remap */ + if ( dom->vpl011_initialized && + vpl011_ring_ref != dom->vpl011_ring_ref && + dom->vpl011_ring_ref != -1 ) + domain_unmap_vpl011_interface(dom); + if (!dom->interface && xgt_handle) { /* Prefer using grant table */ dom->interface = xengnttab_map_grant_ref(xgt_handle, @@ -560,6 +634,8 @@ static int domain_create_ring(struct domain *dom) PROT_READ|PROT_WRITE); dom->ring_ref = -1; } + + /* map PV console ring buffer */ if (!dom->interface) { /* Fall back to xc_map_foreign_range */ dom->interface = xc_map_foreign_range( @@ -573,18 +649,21 @@ static int domain_create_ring(struct domain *dom) dom->ring_ref = ring_ref; } - /* Go no further if port has not changed and we are still bound. */ - if (remote_port == dom->remote_port) { - xc_evtchn_status_t status = { - .dom = DOMID_SELF, - .port = dom->local_port }; - if ((xc_evtchn_status(xc, &status) == 0) && - (status.status == EVTCHNSTAT_interdomain)) + /* map vpl011 console ring buffer */ + if ( dom->vpl011_initialized && !dom->vpl011_interface ) { + + /* Fall back to xc_map_foreign_range */ + dom->vpl011_interface = xc_map_foreign_range( + xc, dom->domid, XC_PAGE_SIZE, + PROT_READ|PROT_WRITE, + (unsigned long)vpl011_ring_ref); + if ( dom->vpl011_interface == NULL ) { + err = EINVAL; goto out; + } + dom->vpl011_ring_ref = vpl011_ring_ref; } - dom->local_port = -1; - dom->remote_port = -1; if (dom->xce_handle != NULL) xenevtchn_close(dom->xce_handle); @@ -596,17 +675,24 @@ static int domain_create_ring(struct domain *dom) goto out; } - rc = xenevtchn_bind_interdomain(dom->xce_handle, - dom->domid, remote_port); - - if (rc == -1) { - err = errno; + /* bind PV console channel */ + err = bind_event_channel(dom, remote_port, &dom->local_port, &dom->remote_port); + if (err) + { xenevtchn_close(dom->xce_handle); - dom->xce_handle = NULL; goto out; } - dom->local_port = rc; - dom->remote_port = remote_port; + + /* bind vpl011 console channel */ + if ( dom->vpl011_initialized ) + { + err = bind_event_channel(dom, vpl011_remote_port, &dom->vpl011_local_port, &dom->vpl011_remote_port); + if (err) + { + xenevtchn_close(dom->xce_handle); + goto out; + } + } if (dom->master_fd == -1) { if (!domain_create_tty(dom)) { @@ -615,6 +701,9 @@ static int domain_create_ring(struct domain *dom) dom->xce_handle = NULL; dom->local_port = -1; dom->remote_port = -1; + dom->vpl011_local_port = -1; + dom->vpl011_remote_port = -1; + dom->vpl011_initialized = false; goto out; } } @@ -684,8 +773,11 @@ static struct domain *create_domain(int domid) dom->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD; dom->ring_ref = -1; + dom->vpl011_ring_ref = -1; dom->local_port = -1; dom->remote_port = -1; + dom->vpl011_local_port = -1; + dom->vpl011_remote_port = -1; if (!watch_domain(dom, true)) goto out;