Received: by 10.192.165.156 with SMTP id m28csp2135541imm; Thu, 12 Apr 2018 09:08:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx48mNH5AzelykuoCX/SLGpKXfvkc3R5z6M+3/B8rQS3ipeJrHT25zNLivlV+rXv9BdfQujMb X-Received: by 10.99.171.11 with SMTP id p11mr1166735pgf.176.1523549324058; Thu, 12 Apr 2018 09:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523549324; cv=none; d=google.com; s=arc-20160816; b=yft8KNjUHzP7j1FdTeroyECYJ1i2MUp6jYKXsv4ocjVIoSmMuISnDOraEEOy+0I9bp UlEPTV5lMZGpcEQvg6peewnFUN8QRzHW0u9DEOAIYyP1ECWdDF31LEg9zBLgEyYn1rEU 4xbk5JEdep8THeejJ6yLfeTAtmBvLw2MHjZMzpMBpr3pPd48/xbyRWE5nU+UDb4SgG68 YayQ+IJyLuoEH3vcj56rXu1YuQq6qTdUSLAgJ2AKObdltkxbdULuS2Z7oRl/DoI63kyi E40tbGInE/75fSsjzez6fKtYeAU7uhUaLTDTEqhVkVM4osTeAeh+fNT5bAT6I3vHj/wU qpMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=iR9DkRS45Pdl3mTBve/HfJVMvivv1Iisrat8iqIR5HI=; b=tap7ZRC7/O3B/y/XdbgklKMQYSxdCfzTSn05DkxaxWDgv5s3t0VW1c5ptw4hm62w/h yKHgRVngLFs0fPWGzovNx7mWLHPZgqyEGbwObra+v6QQTBw2Cq9IA/eb61OLY0r4DnnG Z2tyz46wATPtZixvOZ2vV0lkU5cmxUlYCfhFQ1ILSKH98sFMzw9FoDoLawcNgVRxwg+a 7pNehojhU97n1I08+Y6FmlHeTDbpI0cHtQzxb6P6B3zJ2Ke/d1V8FZWWe0w77BuxUage /elA/K0U2U17FkB7kt0U8buW9y+XJmAcS4NLIBr/24da0LgHhmBhujQFHjJi7gEEhk4M d0Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LGJddlvb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6-v6si3664495plr.661.2018.04.12.09.08.06; Thu, 12 Apr 2018 09:08:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LGJddlvb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752944AbeDLQBl (ORCPT + 99 others); Thu, 12 Apr 2018 12:01:41 -0400 Received: from mail-lf0-f53.google.com ([209.85.215.53]:42084 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752806AbeDLQBe (ORCPT ); Thu, 12 Apr 2018 12:01:34 -0400 Received: by mail-lf0-f53.google.com with SMTP id q9-v6so8466334lfk.9 for ; Thu, 12 Apr 2018 09:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iR9DkRS45Pdl3mTBve/HfJVMvivv1Iisrat8iqIR5HI=; b=LGJddlvbkEDT9Y+PN7pS14ShYNqufG0uP5FqvHP/Sll8NdKiNHZv9p7G1g6rn4CzIo DiIXopulAKvV0VKEYMYxhqBONPDAXwruqQARRiAiw5lQmigqbhRmztC+KFtvNRK2iWye wJFTTkZe0eIlBh/qnjrewMn3mpWkQXDI6cKNL+NjzKw0La+h6fqZm9BTwcGxFL5Wqygf OZiy2F6jqbapZoYOvhRTm3dhm02TzNdRH9XLqstFGbrPdYaLkcMhsa4Da13/94MEcAve IkUsR2MP8Cc/u4+KD3uqY6Avk7erinP7/A1AKnysQUUtaor99hIWkVkxbjVv03OZ2Ar9 dGzQ== 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=iR9DkRS45Pdl3mTBve/HfJVMvivv1Iisrat8iqIR5HI=; b=l+gdWgRMR6qP42mcE7LSvNMRL6Di0beRx6sb7pbuOBLmsnoykMZm1OaOCzDVT51MeS 8y+FM5Tmzz/L51/j/wakB+Yh2pVjuvS7UpjAWvfzsX695wesfcj3ZHzD91sGGvQCjSFh q6Afz7YRZAK/2ADWuRL0N/w7whn+eLIKv6yWdRLp8bz5wrMUQzallrD9JNgUxVXC3BTn lC/Oa/tPGTt7Pymm/e5K4jbjtbC2PBGJbmhP3c1LdDfEJQYAoBZeyvRuULAPq8rMHMfO MqBTV7qkUXK5VBZ+Hm1zKtwuT33k8zMa3KlhMQYpfzZpntp52DqYOSTyNucLX+oqFTkn HK1A== X-Gm-Message-State: ALQs6tAAuk54wwCj691kbT3jrMrHhQhBYvGumVL8Edf7MPc1rH5P11Yx U7uo5qP5P2xf4Eu5BSxv7SI= X-Received: by 2002:a19:5c05:: with SMTP id q5-v6mr1569373lfb.14.1523548891769; Thu, 12 Apr 2018 09:01:31 -0700 (PDT) Received: from localhost.localdomain (207-17-94-178.pool.ukrtel.net. [178.94.17.207]) by smtp.gmail.com with ESMTPSA id m11sm644541ljh.37.2018.04.12.09.01.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Apr 2018 09:01:30 -0700 (PDT) From: Oleksandr Andrushchenko X-Google-Original-From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: boris.ostrovsky@oracle.com, jgross@suse.com, iurii.konovalenko@globallogic.com, oleksandr.dmytryshyn@globallogic.com, konrad.wilk@oracle.com, tiwai@suse.de, andr2000@gmail.com, Oleksandr Grytsov Subject: [PATCH 4/5] xen/sndif: Add explicit back and front synchronization Date: Thu, 12 Apr 2018 19:01:01 +0300 Message-Id: <20180412160102.15833-5-oleksandr_andrushchenko@epam.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180412160102.15833-1-oleksandr_andrushchenko@epam.com> References: <20180412160102.15833-1-oleksandr_andrushchenko@epam.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to provide explicit synchronization between backend and frontend the following changes are introduced in the protocol: - add new ring buffer for sending asynchronous events from backend to frontend to report number of bytes played by the frontend (XENSND_EVT_CUR_POS) - introduce trigger events for playback control: start/stop/pause/resume - add "req-" prefix to event-channel and ring-ref to unify naming of the Xen event channels for requests and events Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Oleksandr Grytsov Cc: Konrad Rzeszutek Wilk Cc: Takashi Iwai --- include/xen/interface/io/sndif.h | 162 ++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 1 deletion(-) diff --git a/include/xen/interface/io/sndif.h b/include/xen/interface/io/sndif.h index d48175f1a3d2..131c3b469d4a 100644 --- a/include/xen/interface/io/sndif.h +++ b/include/xen/interface/io/sndif.h @@ -113,6 +113,8 @@ * * /local/domain/1/device/vsnd/0/0/0/ring-ref = "386" * /local/domain/1/device/vsnd/0/0/0/event-channel = "15" + * /local/domain/1/device/vsnd/0/0/0/evt-ring-ref = "1386" + * /local/domain/1/device/vsnd/0/0/0/evt-event-channel = "215" * *------------------------------ Stream 1, capture ---------------------------- * @@ -122,6 +124,8 @@ * * /local/domain/1/device/vsnd/0/0/1/ring-ref = "384" * /local/domain/1/device/vsnd/0/0/1/event-channel = "13" + * /local/domain/1/device/vsnd/0/0/1/evt-ring-ref = "1384" + * /local/domain/1/device/vsnd/0/0/1/evt-event-channel = "213" * *------------------------------- PCM device 1 -------------------------------- * @@ -135,6 +139,8 @@ * * /local/domain/1/device/vsnd/0/1/0/ring-ref = "387" * /local/domain/1/device/vsnd/0/1/0/event-channel = "151" + * /local/domain/1/device/vsnd/0/1/0/evt-ring-ref = "1387" + * /local/domain/1/device/vsnd/0/1/0/evt-event-channel = "351" * *------------------------------- PCM device 2 -------------------------------- * @@ -147,6 +153,8 @@ * * /local/domain/1/device/vsnd/0/2/0/ring-ref = "389" * /local/domain/1/device/vsnd/0/2/0/event-channel = "152" + * /local/domain/1/device/vsnd/0/2/0/evt-ring-ref = "1389" + * /local/domain/1/device/vsnd/0/2/0/evt-event-channel = "452" * ****************************************************************************** * Backend XenBus Nodes @@ -292,6 +300,23 @@ * The Xen grant reference granting permission for the backend to map * a sole page in a single page sized ring buffer. * + *--------------------- Stream Event Transport Parameters --------------------- + * + * This communication path is used to deliver asynchronous events from backend + * to frontend, set up per stream. + * + * evt-event-channel + * Values: + * + * The identifier of the Xen event channel used to signal activity + * in the ring buffer. + * + * evt-ring-ref + * Values: + * + * The Xen grant reference granting permission for the backend to map + * a sole page in a single page sized ring buffer. + * ****************************************************************************** * STATE DIAGRAMS ****************************************************************************** @@ -439,6 +464,19 @@ #define XENSND_OP_GET_VOLUME 5 #define XENSND_OP_MUTE 6 #define XENSND_OP_UNMUTE 7 +#define XENSND_OP_TRIGGER 8 + +#define XENSND_OP_TRIGGER_START 0 +#define XENSND_OP_TRIGGER_PAUSE 1 +#define XENSND_OP_TRIGGER_STOP 2 +#define XENSND_OP_TRIGGER_RESUME 3 + +/* + ****************************************************************************** + * EVENT CODES + ****************************************************************************** + */ +#define XENSND_EVT_CUR_POS 0 /* ****************************************************************************** @@ -455,6 +493,8 @@ #define XENSND_FIELD_VCARD_LONG_NAME "long-name" #define XENSND_FIELD_RING_REF "ring-ref" #define XENSND_FIELD_EVT_CHNL "event-channel" +#define XENSND_FIELD_EVT_RING_REF "evt-ring-ref" +#define XENSND_FIELD_EVT_EVT_CHNL "evt-event-channel" #define XENSND_FIELD_DEVICE_NAME "name" #define XENSND_FIELD_TYPE "type" #define XENSND_FIELD_STREAM_UNIQUE_ID "unique-id" @@ -566,7 +606,9 @@ * +----------------+----------------+----------------+----------------+ * | gref_directory | 24 * +----------------+----------------+----------------+----------------+ - * | reserved | 28 + * | period_sz | 28 + * +----------------+----------------+----------------+----------------+ + * | reserved | 32 * +----------------+----------------+----------------+----------------+ * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| * +----------------+----------------+----------------+----------------+ @@ -578,6 +620,14 @@ * pcm_channels - uint8_t, number of channels of this stream, * [channels-min; channels-max] * buffer_sz - uint32_t, buffer size to be allocated, octets + * period_sz - uint32_t, event period size, octets + * This is the requested value of the period at which frontend would + * like to receive XENSND_EVT_CUR_POS notifications from the backend when + * stream position advances during playback/capture. + * It shows how many octets are expected to be played/captured before + * sending such an event. + * If set to 0 no XENSND_EVT_CUR_POS events are sent by the backend. + * * gref_directory - grant_ref_t, a reference to the first shared page * describing shared buffer references. At least one page exists. If shared * buffer size (buffer_sz) exceeds what can be addressed by this single page, @@ -592,6 +642,7 @@ struct xensnd_open_req { uint16_t reserved; uint32_t buffer_sz; grant_ref_t gref_directory; + uint32_t period_sz; }; /* @@ -754,8 +805,32 @@ struct xensnd_rw_req { * * The 'struct xensnd_rw_req' is also used for XENSND_OP_SET_VOLUME, * XENSND_OP_GET_VOLUME, XENSND_OP_MUTE, XENSND_OP_UNMUTE. + * + * Request stream running state change - trigger PCM stream running state + * to start, stop, pause or resume: + * + * 0 1 2 3 octet + * +----------------+----------------+----------------+----------------+ + * | id | _OP_TRIGGER | reserved | 4 + * +----------------+----------------+----------------+----------------+ + * | reserved | 8 + * +----------------+----------------+----------------+----------------+ + * | type | reserved | 12 + * +----------------+----------------+----------------+----------------+ + * | reserved | 16 + * +----------------+----------------+----------------+----------------+ + * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| + * +----------------+----------------+----------------+----------------+ + * | reserved | 64 + * +----------------+----------------+----------------+----------------+ + * + * type - uint8_t, XENSND_OP_TRIGGER_XXX value */ +struct xensnd_trigger_req { + uint8_t type; +}; + /* *---------------------------------- Responses -------------------------------- * @@ -778,8 +853,51 @@ struct xensnd_rw_req { * id - uint16_t, copied from the request * operation - uint8_t, XENSND_OP_* - copied from request * status - int32_t, response status, zero on success and -XEN_EXX on failure + * + *----------------------------------- Events ---------------------------------- + * + * Events are sent via shared page allocated by the front and propagated by + * evt-event-channel/evt-ring-ref XenStore entries + * All event packets have the same length (64 octets) + * All event packets have common header: + * 0 1 2 3 octet + * +----------------+----------------+----------------+----------------+ + * | id | type | reserved | 4 + * +----------------+----------------+----------------+----------------+ + * | reserved | 8 + * +----------------+----------------+----------------+----------------+ + * + * id - uint16_t, event id, may be used by front + * type - uint8_t, type of the event + * + * + * Current stream position - event from back to front when stream's + * playback/capture position has advanced: + * 0 1 2 3 octet + * +----------------+----------------+----------------+----------------+ + * | id | _EVT_CUR_POS | reserved | 4 + * +----------------+----------------+----------------+----------------+ + * | reserved | 8 + * +----------------+----------------+----------------+----------------+ + * | position low 32-bit | 12 + * +----------------+----------------+----------------+----------------+ + * | position high 32-bit | 16 + * +----------------+----------------+----------------+----------------+ + * | reserved | 20 + * +----------------+----------------+----------------+----------------+ + * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| + * +----------------+----------------+----------------+----------------+ + * | reserved | 64 + * +----------------+----------------+----------------+----------------+ + * + * position - current value of stream's playback/capture position, octets + * */ +struct xensnd_cur_pos_evt { + uint64_t position; +}; + struct xensnd_req { uint16_t id; uint8_t operation; @@ -787,6 +905,7 @@ struct xensnd_req { union { struct xensnd_open_req open; struct xensnd_rw_req rw; + struct xensnd_trigger_req trigger; uint8_t reserved[56]; } op; }; @@ -799,6 +918,47 @@ struct xensnd_resp { uint8_t reserved1[56]; }; +struct xensnd_evt { + uint16_t id; + uint8_t type; + uint8_t reserved[5]; + union { + struct xensnd_cur_pos_evt cur_pos; + uint8_t reserved[56]; + } op; +}; + DEFINE_RING_TYPES(xen_sndif, struct xensnd_req, struct xensnd_resp); +/* + ****************************************************************************** + * Back to front events delivery + ****************************************************************************** + * In order to deliver asynchronous events from back to front a shared page is + * allocated by front and its granted reference propagated to back via + * XenStore entries (evt-ring-ref/evt-event-channel). + * This page has a common header used by both front and back to synchronize + * access and control event's ring buffer, while back being a producer of the + * events and front being a consumer. The rest of the page after the header + * is used for event packets. + * + * Upon reception of an event(s) front may confirm its reception + * for either each event, group of events or none. + */ + +struct xensnd_event_page { + uint32_t in_cons; + uint32_t in_prod; + uint8_t reserved[56]; +}; + +#define XENSND_EVENT_PAGE_SIZE XEN_PAGE_SIZE +#define XENSND_IN_RING_OFFS (sizeof(struct xensnd_event_page)) +#define XENSND_IN_RING_SIZE (XENSND_EVENT_PAGE_SIZE - XENSND_IN_RING_OFFS) +#define XENSND_IN_RING_LEN (XENSND_IN_RING_SIZE / sizeof(struct xensnd_evt)) +#define XENSND_IN_RING(page) \ + ((struct xensnd_evt *)((char *)(page) + XENSND_IN_RING_OFFS)) +#define XENSND_IN_RING_REF(page, idx) \ + (XENSND_IN_RING((page))[(idx) % XENSND_IN_RING_LEN]) + #endif /* __XEN_PUBLIC_IO_SNDIF_H__ */ -- 2.17.0