2014-03-04 13:58:06 +00:00
|
|
|
/* visorchannel_funcs.c
|
|
|
|
*
|
2014-04-23 18:58:34 +00:00
|
|
|
* Copyright (C) 2010 - 2013 UNISYS CORPORATION
|
2014-03-04 13:58:06 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This provides Supervisor channel communication primitives, which are
|
2015-05-05 22:37:00 +00:00
|
|
|
* independent of the mechanism used to access the channel data.
|
2014-03-04 13:58:06 +00:00
|
|
|
*/
|
|
|
|
|
2015-05-05 22:36:09 +00:00
|
|
|
#include "version.h"
|
2015-05-05 22:36:02 +00:00
|
|
|
#include "visorbus.h"
|
2014-05-06 13:58:23 +00:00
|
|
|
#include <linux/uuid.h>
|
2015-05-13 17:22:18 +00:00
|
|
|
#include "controlvmchannel.h"
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
#define MYDRVNAME "visorchannel"
|
|
|
|
|
2014-12-05 22:09:25 +00:00
|
|
|
struct visorchannel {
|
2015-05-05 22:37:04 +00:00
|
|
|
u64 physaddr;
|
2015-05-05 22:37:00 +00:00
|
|
|
ulong nbytes;
|
|
|
|
void __iomem *mapped;
|
2014-10-23 18:29:55 +00:00
|
|
|
struct channel_header chan_hdr;
|
2014-05-06 13:58:23 +00:00
|
|
|
uuid_le guid;
|
2014-03-04 13:58:06 +00:00
|
|
|
ulong size;
|
2015-05-05 22:37:01 +00:00
|
|
|
bool needs_lock; /* channel creator knows if more than one
|
2014-12-05 22:09:24 +00:00
|
|
|
* thread will be inserting or removing */
|
|
|
|
spinlock_t insert_lock; /* protect head writes in chan_hdr */
|
|
|
|
spinlock_t remove_lock; /* protect tail writes in chan_hdr */
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
struct {
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header req_queue;
|
|
|
|
struct signal_queue_header rsp_queue;
|
|
|
|
struct signal_queue_header event_queue;
|
|
|
|
struct signal_queue_header ack_queue;
|
2014-03-04 13:58:06 +00:00
|
|
|
} safe_uis_queue;
|
2015-05-13 17:22:18 +00:00
|
|
|
uuid_le type;
|
|
|
|
uuid_le inst;
|
2014-03-04 13:58:06 +00:00
|
|
|
};
|
|
|
|
|
2014-12-05 22:09:25 +00:00
|
|
|
/* Creates the struct visorchannel abstraction for a data area in memory,
|
|
|
|
* but does NOT modify this data area.
|
2014-03-04 13:58:06 +00:00
|
|
|
*/
|
2014-12-05 22:09:25 +00:00
|
|
|
static struct visorchannel *
|
2015-05-05 22:37:10 +00:00
|
|
|
visorchannel_create_guts(u64 physaddr, unsigned long channel_bytes,
|
|
|
|
gfp_t gfp, unsigned long off,
|
|
|
|
uuid_le guid, bool needs_lock)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:36:17 +00:00
|
|
|
struct visorchannel *channel;
|
|
|
|
int err;
|
|
|
|
size_t size = sizeof(struct channel_header);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-13 17:22:21 +00:00
|
|
|
if (physaddr == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2015-05-05 22:37:10 +00:00
|
|
|
channel = kzalloc(sizeof(*channel), gfp);
|
2015-05-05 22:36:17 +00:00
|
|
|
if (!channel)
|
2014-11-06 19:13:10 +00:00
|
|
|
goto cleanup;
|
2015-05-05 22:36:17 +00:00
|
|
|
|
|
|
|
channel->needs_lock = needs_lock;
|
|
|
|
spin_lock_init(&channel->insert_lock);
|
|
|
|
spin_lock_init(&channel->remove_lock);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-05 22:36:49 +00:00
|
|
|
if (!request_mem_region(physaddr, size, MYDRVNAME))
|
|
|
|
goto cleanup;
|
2015-05-05 22:36:21 +00:00
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
channel->mapped = ioremap_cache(physaddr, size);
|
|
|
|
if (!channel->mapped) {
|
2015-05-05 22:36:49 +00:00
|
|
|
release_mem_region(physaddr, size);
|
2014-11-06 19:13:10 +00:00
|
|
|
goto cleanup;
|
2015-05-05 22:36:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
channel->physaddr = physaddr;
|
|
|
|
channel->nbytes = size;
|
2015-05-05 22:36:17 +00:00
|
|
|
|
2015-05-05 22:36:57 +00:00
|
|
|
err = visorchannel_read(channel, 0, &channel->chan_hdr,
|
|
|
|
sizeof(struct channel_header));
|
2015-05-05 22:36:17 +00:00
|
|
|
if (err)
|
2014-11-06 19:13:10 +00:00
|
|
|
goto cleanup;
|
2015-05-05 22:36:17 +00:00
|
|
|
|
|
|
|
/* we had better be a CLIENT of this channel */
|
2014-12-05 22:09:22 +00:00
|
|
|
if (channel_bytes == 0)
|
2015-05-05 22:36:17 +00:00
|
|
|
channel_bytes = (ulong)channel->chan_hdr.size;
|
2014-05-06 13:58:23 +00:00
|
|
|
if (uuid_le_cmp(guid, NULL_UUID_LE) == 0)
|
2015-05-05 22:36:17 +00:00
|
|
|
guid = channel->chan_hdr.chtype;
|
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
iounmap(channel->mapped);
|
|
|
|
release_mem_region(channel->physaddr, channel->nbytes);
|
|
|
|
channel->mapped = NULL;
|
|
|
|
if (!request_mem_region(channel->physaddr, channel_bytes, MYDRVNAME))
|
2015-05-05 22:36:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
channel->mapped = ioremap_cache(channel->physaddr, channel_bytes);
|
|
|
|
if (!channel->mapped) {
|
|
|
|
release_mem_region(channel->physaddr, channel_bytes);
|
2014-11-06 19:13:10 +00:00
|
|
|
goto cleanup;
|
2015-05-05 22:36:51 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
channel->nbytes = channel_bytes;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-05 22:36:17 +00:00
|
|
|
channel->size = channel_bytes;
|
|
|
|
channel->guid = guid;
|
|
|
|
return channel;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-05 22:36:17 +00:00
|
|
|
cleanup:
|
|
|
|
visorchannel_destroy(channel);
|
|
|
|
return NULL;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 22:09:25 +00:00
|
|
|
struct visorchannel *
|
2015-05-05 22:37:10 +00:00
|
|
|
visorchannel_create(u64 physaddr, unsigned long channel_bytes,
|
|
|
|
gfp_t gfp, uuid_le guid)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:37:10 +00:00
|
|
|
return visorchannel_create_guts(physaddr, channel_bytes, gfp, 0, guid,
|
2015-05-05 22:37:01 +00:00
|
|
|
false);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_create);
|
|
|
|
|
2014-12-05 22:09:25 +00:00
|
|
|
struct visorchannel *
|
2015-05-05 22:37:10 +00:00
|
|
|
visorchannel_create_with_lock(u64 physaddr, unsigned long channel_bytes,
|
|
|
|
gfp_t gfp, uuid_le guid)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:37:10 +00:00
|
|
|
return visorchannel_create_guts(physaddr, channel_bytes, gfp, 0, guid,
|
2015-05-05 22:37:01 +00:00
|
|
|
true);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_create_with_lock);
|
|
|
|
|
|
|
|
void
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_destroy(struct visorchannel *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-03-16 17:57:44 +00:00
|
|
|
if (!channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
return;
|
2015-05-05 22:37:00 +00:00
|
|
|
if (channel->mapped) {
|
|
|
|
iounmap(channel->mapped);
|
|
|
|
release_mem_region(channel->physaddr, channel->nbytes);
|
2015-05-05 22:36:50 +00:00
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
kfree(channel);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_destroy);
|
|
|
|
|
2015-05-05 22:37:04 +00:00
|
|
|
u64
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_get_physaddr(struct visorchannel *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:37:00 +00:00
|
|
|
return channel->physaddr;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_physaddr);
|
|
|
|
|
|
|
|
ulong
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_get_nbytes(struct visorchannel *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return channel->size;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_nbytes);
|
|
|
|
|
|
|
|
char *
|
2014-05-06 13:58:23 +00:00
|
|
|
visorchannel_uuid_id(uuid_le *guid, char *s)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-05-06 13:58:23 +00:00
|
|
|
sprintf(s, "%pUL", guid);
|
|
|
|
return s;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
2014-05-06 13:58:23 +00:00
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_uuid_id);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
char *
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_id(struct visorchannel *channel, char *s)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-05-06 13:58:23 +00:00
|
|
|
return visorchannel_uuid_id(&channel->guid, s);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_id);
|
|
|
|
|
|
|
|
char *
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_zoneid(struct visorchannel *channel, char *s)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:29:56 +00:00
|
|
|
return visorchannel_uuid_id(&channel->chan_hdr.zone_uuid, s);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_zoneid);
|
|
|
|
|
2015-05-05 22:37:04 +00:00
|
|
|
u64
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_get_clientpartition(struct visorchannel *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:29:56 +00:00
|
|
|
return channel->chan_hdr.partition_handle;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_clientpartition);
|
|
|
|
|
2015-05-13 17:22:20 +00:00
|
|
|
int
|
|
|
|
visorchannel_set_clientpartition(struct visorchannel *channel,
|
|
|
|
u64 partition_handle)
|
|
|
|
{
|
|
|
|
channel->chan_hdr.partition_handle = partition_handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_set_clientpartition);
|
|
|
|
|
2014-05-06 13:58:23 +00:00
|
|
|
uuid_le
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_get_uuid(struct visorchannel *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
return channel->guid;
|
|
|
|
}
|
2014-05-06 13:58:23 +00:00
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_uuid);
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
int
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_read(struct visorchannel *channel, ulong offset,
|
2014-03-04 13:58:06 +00:00
|
|
|
void *local, ulong nbytes)
|
|
|
|
{
|
2015-05-05 22:37:00 +00:00
|
|
|
if (offset + nbytes > channel->nbytes)
|
2015-05-05 22:36:55 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
memcpy_fromio(local, channel->mapped + offset, nbytes);
|
2015-05-05 22:36:18 +00:00
|
|
|
|
2015-05-05 22:36:55 +00:00
|
|
|
return 0;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_read);
|
|
|
|
|
|
|
|
int
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_write(struct visorchannel *channel, ulong offset,
|
2014-03-04 13:58:06 +00:00
|
|
|
void *local, ulong nbytes)
|
|
|
|
{
|
2015-05-05 22:36:56 +00:00
|
|
|
size_t chdr_size = sizeof(struct channel_header);
|
|
|
|
size_t copy_size;
|
2015-05-05 22:36:18 +00:00
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
if (offset + nbytes > channel->nbytes)
|
2015-05-05 22:36:54 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2015-05-05 22:36:56 +00:00
|
|
|
if (offset < chdr_size) {
|
|
|
|
copy_size = min(chdr_size, nbytes) - offset;
|
|
|
|
memcpy(&channel->chan_hdr + offset, local, copy_size);
|
|
|
|
}
|
2015-05-05 22:36:54 +00:00
|
|
|
|
2015-05-05 22:37:00 +00:00
|
|
|
memcpy_toio(channel->mapped + offset, local, nbytes);
|
2015-05-05 22:36:54 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_write);
|
|
|
|
|
|
|
|
int
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_clear(struct visorchannel *channel, ulong offset, u8 ch,
|
|
|
|
ulong nbytes)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:36:18 +00:00
|
|
|
int err;
|
2015-05-05 22:36:29 +00:00
|
|
|
int bufsize = PAGE_SIZE;
|
2014-03-04 13:58:06 +00:00
|
|
|
int written = 0;
|
2015-05-05 22:36:18 +00:00
|
|
|
u8 *buf;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-05 22:36:29 +00:00
|
|
|
buf = (u8 *) __get_free_page(GFP_KERNEL);
|
2015-03-16 17:57:44 +00:00
|
|
|
if (!buf)
|
2015-05-05 22:36:18 +00:00
|
|
|
return -ENOMEM;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
memset(buf, ch, bufsize);
|
2015-05-05 22:36:29 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
while (nbytes > 0) {
|
2015-05-05 22:36:29 +00:00
|
|
|
int thisbytes = bufsize;
|
2014-09-29 10:19:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
if (nbytes < thisbytes)
|
|
|
|
thisbytes = nbytes;
|
2015-05-05 22:36:59 +00:00
|
|
|
err = visorchannel_write(channel, offset + written,
|
|
|
|
buf, thisbytes);
|
2015-05-05 22:36:18 +00:00
|
|
|
if (err)
|
2014-11-06 19:13:10 +00:00
|
|
|
goto cleanup;
|
2015-05-05 22:36:18 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
written += thisbytes;
|
|
|
|
nbytes -= thisbytes;
|
|
|
|
}
|
2015-05-05 22:36:28 +00:00
|
|
|
err = 0;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2014-11-06 19:13:10 +00:00
|
|
|
cleanup:
|
2015-05-05 22:36:29 +00:00
|
|
|
free_page((unsigned long) buf);
|
2015-05-05 22:36:18 +00:00
|
|
|
return err;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_clear);
|
|
|
|
|
2014-05-22 17:31:09 +00:00
|
|
|
void __iomem *
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_get_header(struct visorchannel *channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-11-06 19:13:07 +00:00
|
|
|
return (void __iomem *)&channel->chan_hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_get_header);
|
|
|
|
|
|
|
|
/** Return offset of a specific SIGNAL_QUEUE_HEADER from the beginning of a
|
|
|
|
* channel header
|
|
|
|
*/
|
|
|
|
#define SIG_QUEUE_OFFSET(chan_hdr, q) \
|
2014-10-23 18:30:03 +00:00
|
|
|
((chan_hdr)->ch_space_offset + \
|
|
|
|
((q) * sizeof(struct signal_queue_header)))
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/** Return offset of a specific queue entry (data) from the beginning of a
|
|
|
|
* channel header
|
|
|
|
*/
|
|
|
|
#define SIG_DATA_OFFSET(chan_hdr, q, sig_hdr, slot) \
|
2014-10-23 18:30:04 +00:00
|
|
|
(SIG_QUEUE_OFFSET(chan_hdr, q) + (sig_hdr)->sig_base_offset + \
|
|
|
|
((slot) * (sig_hdr)->signal_size))
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/** Write the contents of a specific field within a SIGNAL_QUEUE_HEADER back
|
|
|
|
* into host memory
|
|
|
|
*/
|
2015-05-05 22:36:59 +00:00
|
|
|
#define SIG_WRITE_FIELD(channel, queue, sig_hdr, FIELD) \
|
|
|
|
(visorchannel_write(channel, \
|
|
|
|
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)+ \
|
|
|
|
offsetof(struct signal_queue_header, FIELD), \
|
|
|
|
&((sig_hdr)->FIELD), \
|
|
|
|
sizeof((sig_hdr)->FIELD)) >= 0)
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
static bool
|
2014-12-05 22:09:25 +00:00
|
|
|
sig_read_header(struct visorchannel *channel, u32 queue,
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header *sig_hdr)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:36:18 +00:00
|
|
|
int err;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-03-04 17:14:25 +00:00
|
|
|
if (channel->chan_hdr.ch_space_offset < sizeof(struct channel_header))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */
|
2015-05-05 22:36:58 +00:00
|
|
|
err = visorchannel_read(channel,
|
|
|
|
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue),
|
|
|
|
sig_hdr, sizeof(struct signal_queue_header));
|
2015-05-05 22:36:18 +00:00
|
|
|
if (err)
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
return true;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
static inline bool
|
2015-05-05 22:36:19 +00:00
|
|
|
sig_read_data(struct visorchannel *channel, u32 queue,
|
|
|
|
struct signal_queue_header *sig_hdr, u32 slot, void *data)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:36:18 +00:00
|
|
|
int err;
|
2014-03-04 13:58:06 +00:00
|
|
|
int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue,
|
|
|
|
sig_hdr, slot);
|
|
|
|
|
2015-05-05 22:36:58 +00:00
|
|
|
err = visorchannel_read(channel, signal_data_offset,
|
|
|
|
data, sig_hdr->signal_size);
|
2015-05-05 22:36:19 +00:00
|
|
|
if (err)
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-05-05 22:36:19 +00:00
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
return true;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
static inline bool
|
2014-12-05 22:09:25 +00:00
|
|
|
sig_write_data(struct visorchannel *channel, u32 queue,
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header *sig_hdr, u32 slot, void *data)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:36:19 +00:00
|
|
|
int err;
|
|
|
|
int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue,
|
|
|
|
sig_hdr, slot);
|
|
|
|
|
2015-05-05 22:36:59 +00:00
|
|
|
err = visorchannel_write(channel, signal_data_offset,
|
|
|
|
data, sig_hdr->signal_size);
|
2015-05-05 22:36:19 +00:00
|
|
|
if (err)
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-05-05 22:36:19 +00:00
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
return true;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
static bool
|
2015-01-17 11:39:53 +00:00
|
|
|
signalremove_inner(struct visorchannel *channel, u32 queue, void *msg)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-02-18 18:53:41 +00:00
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-01-17 11:39:53 +00:00
|
|
|
if (sig_hdr.head == sig_hdr.tail)
|
2015-05-05 22:37:01 +00:00
|
|
|
return false; /* no signals to remove */
|
2015-01-17 11:39:53 +00:00
|
|
|
|
2014-10-23 18:30:04 +00:00
|
|
|
sig_hdr.tail = (sig_hdr.tail + 1) % sig_hdr.max_slots;
|
2015-04-04 23:09:30 +00:00
|
|
|
if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.tail, msg))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2014-10-23 18:30:04 +00:00
|
|
|
sig_hdr.num_received++;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/* For each data field in SIGNAL_QUEUE_HEADER that was modified,
|
|
|
|
* update host memory.
|
|
|
|
*/
|
2014-08-03 02:03:38 +00:00
|
|
|
mb(); /* required for channel synch */
|
2015-03-04 17:14:25 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, tail))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-03-04 17:14:25 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_received))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2015-01-17 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
bool
|
2015-01-17 11:39:53 +00:00
|
|
|
visorchannel_signalremove(struct visorchannel *channel, u32 queue, void *msg)
|
|
|
|
{
|
2015-05-05 22:37:01 +00:00
|
|
|
bool rc;
|
2015-01-17 11:39:53 +00:00
|
|
|
|
|
|
|
if (channel->needs_lock) {
|
|
|
|
spin_lock(&channel->remove_lock);
|
|
|
|
rc = signalremove_inner(channel, queue, msg);
|
2014-03-04 13:58:06 +00:00
|
|
|
spin_unlock(&channel->remove_lock);
|
2015-01-17 11:39:53 +00:00
|
|
|
} else {
|
|
|
|
rc = signalremove_inner(channel, queue, msg);
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalremove);
|
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
static bool
|
2015-01-17 11:39:53 +00:00
|
|
|
signalinsert_inner(struct visorchannel *channel, u32 queue, void *msg)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2015-02-18 18:53:41 +00:00
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
2014-10-23 18:30:04 +00:00
|
|
|
sig_hdr.head = ((sig_hdr.head + 1) % sig_hdr.max_slots);
|
|
|
|
if (sig_hdr.head == sig_hdr.tail) {
|
|
|
|
sig_hdr.num_overflows++;
|
2015-05-05 22:36:59 +00:00
|
|
|
visorchannel_write(channel,
|
|
|
|
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue) +
|
|
|
|
offsetof(struct signal_queue_header,
|
|
|
|
num_overflows),
|
|
|
|
&(sig_hdr.num_overflows),
|
|
|
|
sizeof(sig_hdr.num_overflows));
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 17:14:25 +00:00
|
|
|
if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.head, msg))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2014-10-23 18:30:04 +00:00
|
|
|
sig_hdr.num_sent++;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
/* For each data field in SIGNAL_QUEUE_HEADER that was modified,
|
|
|
|
* update host memory.
|
|
|
|
*/
|
2014-08-03 02:03:38 +00:00
|
|
|
mb(); /* required for channel synch */
|
2015-03-04 17:14:25 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, head))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-04-04 23:09:30 +00:00
|
|
|
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_sent))
|
2015-05-05 22:37:01 +00:00
|
|
|
return false;
|
2015-01-17 11:39:53 +00:00
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
return true;
|
2015-01-17 11:39:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 22:37:01 +00:00
|
|
|
bool
|
2015-01-17 11:39:53 +00:00
|
|
|
visorchannel_signalinsert(struct visorchannel *channel, u32 queue, void *msg)
|
|
|
|
{
|
2015-05-05 22:37:01 +00:00
|
|
|
bool rc;
|
2015-01-17 11:39:53 +00:00
|
|
|
|
|
|
|
if (channel->needs_lock) {
|
|
|
|
spin_lock(&channel->insert_lock);
|
|
|
|
rc = signalinsert_inner(channel, queue, msg);
|
2014-03-04 13:58:06 +00:00
|
|
|
spin_unlock(&channel->insert_lock);
|
2015-01-17 11:39:53 +00:00
|
|
|
} else {
|
|
|
|
rc = signalinsert_inner(channel, queue, msg);
|
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalinsert);
|
|
|
|
|
|
|
|
int
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_signalqueue_slots_avail(struct visorchannel *channel, u32 queue)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-07-31 16:00:50 +00:00
|
|
|
u32 slots_avail, slots_used;
|
|
|
|
u32 head, tail;
|
2014-03-04 13:58:06 +00:00
|
|
|
|
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr))
|
|
|
|
return 0;
|
2014-10-23 18:30:04 +00:00
|
|
|
head = sig_hdr.head;
|
|
|
|
tail = sig_hdr.tail;
|
2014-03-04 13:58:06 +00:00
|
|
|
if (head < tail)
|
2014-10-23 18:30:04 +00:00
|
|
|
head = head + sig_hdr.max_slots;
|
2014-03-04 13:58:06 +00:00
|
|
|
slots_used = (head - tail);
|
2014-10-23 18:30:04 +00:00
|
|
|
slots_avail = sig_hdr.max_signals - slots_used;
|
2014-11-06 19:13:06 +00:00
|
|
|
return (int)slots_avail;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalqueue_slots_avail);
|
|
|
|
|
|
|
|
int
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header sig_hdr;
|
2014-09-29 10:19:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
if (!sig_read_header(channel, queue, &sig_hdr))
|
|
|
|
return 0;
|
2014-11-06 19:13:06 +00:00
|
|
|
return (int)sig_hdr.max_signals;
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_signalqueue_max_slots);
|
|
|
|
|
|
|
|
static void
|
2014-10-23 18:30:03 +00:00
|
|
|
sigqueue_debug(struct signal_queue_header *q, int which, struct seq_file *seq)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
|
|
|
seq_printf(seq, "Signal Queue #%d\n", which);
|
2014-10-23 18:30:04 +00:00
|
|
|
seq_printf(seq, " VersionId = %lu\n", (ulong)q->version);
|
|
|
|
seq_printf(seq, " Type = %lu\n", (ulong)q->chtype);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, " oSignalBase = %llu\n",
|
2014-10-23 18:30:04 +00:00
|
|
|
(long long)q->sig_base_offset);
|
|
|
|
seq_printf(seq, " SignalSize = %lu\n", (ulong)q->signal_size);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, " MaxSignalSlots = %lu\n",
|
2014-10-23 18:30:04 +00:00
|
|
|
(ulong)q->max_slots);
|
|
|
|
seq_printf(seq, " MaxSignals = %lu\n", (ulong)q->max_signals);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, " FeatureFlags = %-16.16Lx\n",
|
2014-10-23 18:30:04 +00:00
|
|
|
(long long)q->features);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, " NumSignalsSent = %llu\n",
|
2014-10-23 18:30:04 +00:00
|
|
|
(long long)q->num_sent);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, " NumSignalsReceived = %llu\n",
|
2014-10-23 18:30:04 +00:00
|
|
|
(long long)q->num_received);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, " NumOverflows = %llu\n",
|
2014-10-23 18:30:04 +00:00
|
|
|
(long long)q->num_overflows);
|
|
|
|
seq_printf(seq, " Head = %lu\n", (ulong)q->head);
|
|
|
|
seq_printf(seq, " Tail = %lu\n", (ulong)q->tail);
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-05 22:09:25 +00:00
|
|
|
visorchannel_debug(struct visorchannel *channel, int num_queues,
|
2014-07-31 16:00:50 +00:00
|
|
|
struct seq_file *seq, u32 off)
|
2014-03-04 13:58:06 +00:00
|
|
|
{
|
2015-05-05 22:37:04 +00:00
|
|
|
u64 addr = 0;
|
2014-03-04 13:58:06 +00:00
|
|
|
ulong nbytes = 0, nbytes_region = 0;
|
2014-10-23 18:29:55 +00:00
|
|
|
struct channel_header hdr;
|
|
|
|
struct channel_header *phdr = &hdr;
|
2014-03-04 13:58:06 +00:00
|
|
|
int i = 0;
|
|
|
|
int errcode = 0;
|
|
|
|
|
2015-03-16 17:57:44 +00:00
|
|
|
if (!channel)
|
2014-03-04 13:58:06 +00:00
|
|
|
return;
|
2015-03-04 17:14:25 +00:00
|
|
|
|
2015-05-05 22:36:52 +00:00
|
|
|
addr = visorchannel_get_physaddr(channel);
|
|
|
|
nbytes_region = visorchannel_get_nbytes(channel);
|
2014-03-04 13:58:06 +00:00
|
|
|
errcode = visorchannel_read(channel, off,
|
2014-10-23 18:29:55 +00:00
|
|
|
phdr, sizeof(struct channel_header));
|
2014-03-04 13:58:06 +00:00
|
|
|
if (errcode < 0) {
|
|
|
|
seq_printf(seq,
|
|
|
|
"Read of channel header failed with errcode=%d)\n",
|
|
|
|
errcode);
|
|
|
|
if (off == 0) {
|
|
|
|
phdr = &channel->chan_hdr;
|
|
|
|
seq_puts(seq, "(following data may be stale)\n");
|
2014-11-06 19:13:11 +00:00
|
|
|
} else {
|
2014-03-04 13:58:06 +00:00
|
|
|
return;
|
2014-11-06 19:13:11 +00:00
|
|
|
}
|
2014-03-04 13:58:06 +00:00
|
|
|
}
|
2014-11-06 19:13:06 +00:00
|
|
|
nbytes = (ulong)(phdr->size);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "--- Begin channel @0x%-16.16Lx for 0x%lx bytes (region=0x%lx bytes) ---\n",
|
|
|
|
addr + off, nbytes, nbytes_region);
|
2014-10-23 18:29:56 +00:00
|
|
|
seq_printf(seq, "Type = %pUL\n", &phdr->chtype);
|
|
|
|
seq_printf(seq, "ZoneGuid = %pUL\n", &phdr->zone_uuid);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "Signature = 0x%-16.16Lx\n",
|
2014-11-06 19:13:06 +00:00
|
|
|
(long long)phdr->signature);
|
2014-10-23 18:29:56 +00:00
|
|
|
seq_printf(seq, "LegacyState = %lu\n", (ulong)phdr->legacy_state);
|
|
|
|
seq_printf(seq, "SrvState = %lu\n", (ulong)phdr->srv_state);
|
|
|
|
seq_printf(seq, "CliStateBoot = %lu\n", (ulong)phdr->cli_state_boot);
|
|
|
|
seq_printf(seq, "CliStateOS = %lu\n", (ulong)phdr->cli_state_os);
|
|
|
|
seq_printf(seq, "HeaderSize = %lu\n", (ulong)phdr->header_size);
|
|
|
|
seq_printf(seq, "Size = %llu\n", (long long)phdr->size);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "Features = 0x%-16.16llx\n",
|
2014-11-06 19:13:06 +00:00
|
|
|
(long long)phdr->features);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "PartitionHandle = 0x%-16.16llx\n",
|
2014-11-06 19:13:06 +00:00
|
|
|
(long long)phdr->partition_handle);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "Handle = 0x%-16.16llx\n",
|
2014-11-06 19:13:06 +00:00
|
|
|
(long long)phdr->handle);
|
|
|
|
seq_printf(seq, "VersionId = %lu\n", (ulong)phdr->version_id);
|
2014-03-04 13:58:06 +00:00
|
|
|
seq_printf(seq, "oChannelSpace = %llu\n",
|
2014-11-06 19:13:06 +00:00
|
|
|
(long long)phdr->ch_space_offset);
|
2014-10-23 18:29:56 +00:00
|
|
|
if ((phdr->ch_space_offset == 0) || (errcode < 0))
|
2014-03-04 13:58:06 +00:00
|
|
|
;
|
|
|
|
else
|
2014-12-05 22:09:23 +00:00
|
|
|
for (i = 0; i < num_queues; i++) {
|
2014-10-23 18:30:03 +00:00
|
|
|
struct signal_queue_header q;
|
2014-09-29 10:19:25 +00:00
|
|
|
|
2014-03-04 13:58:06 +00:00
|
|
|
errcode = visorchannel_read(channel,
|
2014-11-06 19:13:05 +00:00
|
|
|
off +
|
|
|
|
phdr->ch_space_offset +
|
|
|
|
(i * sizeof(q)),
|
|
|
|
&q, sizeof(q));
|
2014-03-04 13:58:06 +00:00
|
|
|
if (errcode < 0) {
|
|
|
|
seq_printf(seq,
|
|
|
|
"failed to read signal queue #%d from channel @0x%-16.16Lx errcode=%d\n",
|
|
|
|
i, addr, errcode);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sigqueue_debug(&q, i, seq);
|
|
|
|
}
|
|
|
|
seq_printf(seq, "--- End channel @0x%-16.16Lx for 0x%lx bytes ---\n",
|
|
|
|
addr + off, nbytes);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(visorchannel_debug);
|