Commit 96382b4f authored by Takashi Iwai's avatar Takashi Iwai

Merge branch 'topic/xen' into for-next

Merge Xen para-virtualized frontend driver from Oleksandr Andrushchenko.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parents d0aa5909 190a5f2e
...@@ -15494,6 +15494,13 @@ S: Supported ...@@ -15494,6 +15494,13 @@ S: Supported
F: arch/x86/xen/*swiotlb* F: arch/x86/xen/*swiotlb*
F: drivers/xen/*swiotlb* F: drivers/xen/*swiotlb*
XEN SOUND FRONTEND DRIVER
M: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
L: alsa-devel@alsa-project.org (moderated for non-subscribers)
S: Supported
F: sound/xen/*
XFS FILESYSTEM XFS FILESYSTEM
M: Darrick J. Wong <darrick.wong@oracle.com> M: Darrick J. Wong <darrick.wong@oracle.com>
M: linux-xfs@vger.kernel.org M: linux-xfs@vger.kernel.org
......
...@@ -96,6 +96,8 @@ source "sound/x86/Kconfig" ...@@ -96,6 +96,8 @@ source "sound/x86/Kconfig"
source "sound/synth/Kconfig" source "sound/synth/Kconfig"
source "sound/xen/Kconfig"
endif # SND endif # SND
endif # !UML endif # !UML
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
obj-$(CONFIG_SOUND) += soundcore.o obj-$(CONFIG_SOUND) += soundcore.o
obj-$(CONFIG_DMASOUND) += oss/dmasound/ obj-$(CONFIG_DMASOUND) += oss/dmasound/
obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/ firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/ xen/
obj-$(CONFIG_SND_AOA) += aoa/ obj-$(CONFIG_SND_AOA) += aoa/
# This one must be compilable even if sound is configured out # This one must be compilable even if sound is configured out
......
# ALSA Xen drivers
config SND_XEN_FRONTEND
tristate "Xen para-virtualized sound frontend driver"
depends on XEN
select SND_PCM
select XEN_XENBUS_FRONTEND
help
Choose this option if you want to enable a para-virtualized
frontend sound driver for Xen guest OSes.
# SPDX-License-Identifier: GPL-2.0 OR MIT
snd_xen_front-objs := xen_snd_front.o \
xen_snd_front_cfg.o \
xen_snd_front_evtchnl.o \
xen_snd_front_shbuf.o \
xen_snd_front_alsa.o
obj-$(CONFIG_SND_XEN_FRONTEND) += snd_xen_front.o
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
* Xen para-virtual sound device
*
* Copyright (C) 2016-2018 EPAM Systems Inc.
*
* Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
*/
#ifndef __XEN_SND_FRONT_H
#define __XEN_SND_FRONT_H
#include "xen_snd_front_cfg.h"
struct xen_snd_front_card_info;
struct xen_snd_front_evtchnl;
struct xen_snd_front_evtchnl_pair;
struct xen_snd_front_shbuf;
struct xensnd_query_hw_param;
struct xen_snd_front_info {
struct xenbus_device *xb_dev;
struct xen_snd_front_card_info *card_info;
int num_evt_pairs;
struct xen_snd_front_evtchnl_pair *evt_pairs;
struct xen_front_cfg_card cfg;
};
int xen_snd_front_stream_query_hw_param(struct xen_snd_front_evtchnl *evtchnl,
struct xensnd_query_hw_param *hw_param_req,
struct xensnd_query_hw_param *hw_param_resp);
int xen_snd_front_stream_prepare(struct xen_snd_front_evtchnl *evtchnl,
struct xen_snd_front_shbuf *sh_buf,
u8 format, unsigned int channels,
unsigned int rate, u32 buffer_sz,
u32 period_sz);
int xen_snd_front_stream_close(struct xen_snd_front_evtchnl *evtchnl);
int xen_snd_front_stream_write(struct xen_snd_front_evtchnl *evtchnl,
unsigned long pos, unsigned long count);
int xen_snd_front_stream_read(struct xen_snd_front_evtchnl *evtchnl,
unsigned long pos, unsigned long count);
int xen_snd_front_stream_trigger(struct xen_snd_front_evtchnl *evtchnl,
int type);
#endif /* __XEN_SND_FRONT_H */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
* Xen para-virtual sound device
*
* Copyright (C) 2016-2018 EPAM Systems Inc.
*
* Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
*/
#ifndef __XEN_SND_FRONT_ALSA_H
#define __XEN_SND_FRONT_ALSA_H
struct xen_snd_front_info;
int xen_snd_front_alsa_init(struct xen_snd_front_info *front_info);
void xen_snd_front_alsa_fini(struct xen_snd_front_info *front_info);
void xen_snd_front_alsa_handle_cur_pos(struct xen_snd_front_evtchnl *evtchnl,
u64 pos_bytes);
#endif /* __XEN_SND_FRONT_ALSA_H */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
* Xen para-virtual sound device
*
* Copyright (C) 2016-2018 EPAM Systems Inc.
*
* Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
*/
#ifndef __XEN_SND_FRONT_CFG_H
#define __XEN_SND_FRONT_CFG_H
#include <sound/core.h>
#include <sound/pcm.h>
struct xen_snd_front_info;
struct xen_front_cfg_stream {
int index;
char *xenstore_path;
struct snd_pcm_hardware pcm_hw;
};
struct xen_front_cfg_pcm_instance {
char name[80];
int device_id;
struct snd_pcm_hardware pcm_hw;
int num_streams_pb;
struct xen_front_cfg_stream *streams_pb;
int num_streams_cap;
struct xen_front_cfg_stream *streams_cap;
};
struct xen_front_cfg_card {
char name_short[32];
char name_long[80];
struct snd_pcm_hardware pcm_hw;
int num_pcm_instances;
struct xen_front_cfg_pcm_instance *pcm_instances;
};
int xen_snd_front_cfg_card(struct xen_snd_front_info *front_info,
int *stream_cnt);
#endif /* __XEN_SND_FRONT_CFG_H */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
* Xen para-virtual sound device
*
* Copyright (C) 2016-2018 EPAM Systems Inc.
*
* Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
*/
#ifndef __XEN_SND_FRONT_EVTCHNL_H
#define __XEN_SND_FRONT_EVTCHNL_H
#include <xen/interface/io/sndif.h>
struct xen_snd_front_info;
#ifndef GRANT_INVALID_REF
/*
* FIXME: usage of grant reference 0 as invalid grant reference:
* grant reference 0 is valid, but never exposed to a PV driver,
* because of the fact it is already in use/reserved by the PV console.
*/
#define GRANT_INVALID_REF 0
#endif
/* Timeout in ms to wait for backend to respond. */
#define VSND_WAIT_BACK_MS 3000
enum xen_snd_front_evtchnl_state {
EVTCHNL_STATE_DISCONNECTED,
EVTCHNL_STATE_CONNECTED,
};
enum xen_snd_front_evtchnl_type {
EVTCHNL_TYPE_REQ,
EVTCHNL_TYPE_EVT,
};
struct xen_snd_front_evtchnl {
struct xen_snd_front_info *front_info;
int gref;
int port;
int irq;
int index;
/* State of the event channel. */
enum xen_snd_front_evtchnl_state state;
enum xen_snd_front_evtchnl_type type;
/* Either response id or incoming event id. */
u16 evt_id;
/* Next request id or next expected event id. */
u16 evt_next_id;
/* Shared ring access lock. */
struct mutex ring_io_lock;
union {
struct {
struct xen_sndif_front_ring ring;
struct completion completion;
/* Serializer for backend IO: request/response. */
struct mutex req_io_lock;
/* Latest response status. */
int resp_status;
union {
struct xensnd_query_hw_param hw_param;
} resp;
} req;
struct {
struct xensnd_event_page *page;
/* This is needed to handle XENSND_EVT_CUR_POS event. */
struct snd_pcm_substream *substream;
} evt;
} u;
};
struct xen_snd_front_evtchnl_pair {
struct xen_snd_front_evtchnl req;
struct xen_snd_front_evtchnl evt;
};
int xen_snd_front_evtchnl_create_all(struct xen_snd_front_info *front_info,
int num_streams);
void xen_snd_front_evtchnl_free_all(struct xen_snd_front_info *front_info);
int xen_snd_front_evtchnl_publish_all(struct xen_snd_front_info *front_info);
void xen_snd_front_evtchnl_flush(struct xen_snd_front_evtchnl *evtchnl);
void xen_snd_front_evtchnl_pair_set_connected(struct xen_snd_front_evtchnl_pair *evt_pair,
bool is_connected);
void xen_snd_front_evtchnl_pair_clear(struct xen_snd_front_evtchnl_pair *evt_pair);
#endif /* __XEN_SND_FRONT_EVTCHNL_H */
// SPDX-License-Identifier: GPL-2.0 OR MIT
/*
* Xen para-virtual sound device
*
* Copyright (C) 2016-2018 EPAM Systems Inc.
*
* Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
*/
#include <linux/kernel.h>
#include <xen/xen.h>
#include <xen/xenbus.h>
#include "xen_snd_front_shbuf.h"
grant_ref_t xen_snd_front_shbuf_get_dir_start(struct xen_snd_front_shbuf *buf)
{
if (!buf->grefs)
return GRANT_INVALID_REF;
return buf->grefs[0];
}
void xen_snd_front_shbuf_clear(struct xen_snd_front_shbuf *buf)
{
memset(buf, 0, sizeof(*buf));
}
void xen_snd_front_shbuf_free(struct xen_snd_front_shbuf *buf)
{
int i;
if (buf->grefs) {
for (i = 0; i < buf->num_grefs; i++)
if (buf->grefs[i] != GRANT_INVALID_REF)
gnttab_end_foreign_access(buf->grefs[i],
0, 0UL);
kfree(buf->grefs);
}
kfree(buf->directory);
free_pages_exact(buf->buffer, buf->buffer_sz);
xen_snd_front_shbuf_clear(buf);
}
/*
* number of grant references a page can hold with respect to the
* xensnd_page_directory header
*/
#define XENSND_NUM_GREFS_PER_PAGE ((XEN_PAGE_SIZE - \
offsetof(struct xensnd_page_directory, gref)) / \
sizeof(grant_ref_t))
static void fill_page_dir(struct xen_snd_front_shbuf *buf,
int num_pages_dir)
{
struct xensnd_page_directory *page_dir;
unsigned char *ptr;
int i, cur_gref, grefs_left, to_copy;
ptr = buf->directory;
grefs_left = buf->num_grefs - num_pages_dir;
/*
* skip grant references at the beginning, they are for pages granted
* for the page directory itself
*/
cur_gref = num_pages_dir;
for (i = 0; i < num_pages_dir; i++) {
page_dir = (struct xensnd_page_directory *)ptr;
if (grefs_left <= XENSND_NUM_GREFS_PER_PAGE) {
to_copy = grefs_left;
page_dir->gref_dir_next_page = GRANT_INVALID_REF;
} else {
to_copy = XENSND_NUM_GREFS_PER_PAGE;
page_dir->gref_dir_next_page = buf->grefs[i + 1];
}
memcpy(&page_dir->gref, &buf->grefs[cur_gref],
to_copy * sizeof(grant_ref_t));
ptr += XEN_PAGE_SIZE;
grefs_left -= to_copy;
cur_gref += to_copy;
}
}
static int grant_references(struct xenbus_device *xb_dev,
struct xen_snd_front_shbuf *buf,
int num_pages_dir, int num_pages_buffer,
int num_grefs)
{
grant_ref_t priv_gref_head;
unsigned long frame;
int ret, i, j, cur_ref;
int otherend_id;
ret = gnttab_alloc_grant_references(num_grefs, &priv_gref_head);
if (ret)
return ret;
buf->num_grefs = num_grefs;
otherend_id = xb_dev->otherend_id;
j = 0;
for (i = 0; i < num_pages_dir; i++) {
cur_ref = gnttab_claim_grant_reference(&priv_gref_head);
if (cur_ref < 0) {
ret = cur_ref;
goto fail;
}
frame = xen_page_to_gfn(virt_to_page(buf->directory +
XEN_PAGE_SIZE * i));
gnttab_grant_foreign_access_ref(cur_ref, otherend_id, frame, 0);
buf->grefs[j++] = cur_ref;
}
for (i = 0; i < num_pages_buffer; i++) {
cur_ref = gnttab_claim_grant_reference(&priv_gref_head);
if (cur_ref < 0) {
ret = cur_ref;
goto fail;
}
frame = xen_page_to_gfn(virt_to_page(buf->buffer +
XEN_PAGE_SIZE * i));
gnttab_grant_foreign_access_ref(cur_ref, otherend_id, frame, 0);
buf->grefs[j++] = cur_ref;
}
gnttab_free_grant_references(priv_gref_head);
fill_page_dir(buf, num_pages_dir);
return 0;
fail:
gnttab_free_grant_references(priv_gref_head);
return ret;
}
static int alloc_int_buffers(struct xen_snd_front_shbuf *buf,
int num_pages_dir, int num_pages_buffer,
int num_grefs)
{
buf->grefs = kcalloc(num_grefs, sizeof(*buf->grefs), GFP_KERNEL);
if (!buf->grefs)
return -ENOMEM;
buf->directory = kcalloc(num_pages_dir, XEN_PAGE_SIZE, GFP_KERNEL);
if (!buf->directory)
goto fail;
buf->buffer_sz = num_pages_buffer * XEN_PAGE_SIZE;
buf->buffer = alloc_pages_exact(buf->buffer_sz, GFP_KERNEL);
if (!buf->buffer)
goto fail;
return 0;
fail:
kfree(buf->grefs);
buf->grefs = NULL;
kfree(buf->directory);
buf->directory = NULL;
return -ENOMEM;
}
int xen_snd_front_shbuf_alloc(struct xenbus_device *xb_dev,
struct xen_snd_front_shbuf *buf,
unsigned int buffer_sz)
{
int num_pages_buffer, num_pages_dir, num_grefs;
int ret;
xen_snd_front_shbuf_clear(buf);
num_pages_buffer = DIV_ROUND_UP(buffer_sz, XEN_PAGE_SIZE);
/* number of pages the page directory consumes itself */
num_pages_dir = DIV_ROUND_UP(num_pages_buffer,
XENSND_NUM_GREFS_PER_PAGE);
num_grefs = num_pages_buffer + num_pages_dir;
ret = alloc_int_buffers(buf, num_pages_dir,
num_pages_buffer, num_grefs);
if (ret < 0)
return ret;
ret = grant_references(xb_dev, buf, num_pages_dir, num_pages_buffer,
num_grefs);
if (ret < 0)
return ret;
fill_page_dir(buf, num_pages_dir);
return 0;
}
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
* Xen para-virtual sound device
*
* Copyright (C) 2016-2018 EPAM Systems Inc.
*
* Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
*/
#ifndef __XEN_SND_FRONT_SHBUF_H
#define __XEN_SND_FRONT_SHBUF_H
#include <xen/grant_table.h>
#include "xen_snd_front_evtchnl.h"
struct xen_snd_front_shbuf {
int num_grefs;
grant_ref_t *grefs;
u8 *directory;
u8 *buffer;
size_t buffer_sz;
};
grant_ref_t xen_snd_front_shbuf_get_dir_start(struct xen_snd_front_shbuf *buf);
int xen_snd_front_shbuf_alloc(struct xenbus_device *xb_dev,
struct xen_snd_front_shbuf *buf,
unsigned int buffer_sz);
void xen_snd_front_shbuf_clear(struct xen_snd_front_shbuf *buf);
void xen_snd_front_shbuf_free(struct xen_snd_front_shbuf *buf);
#endif /* __XEN_SND_FRONT_SHBUF_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment