* [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input
@ 2017-06-06 10:04 Bhupinder Thakur
0 siblings, 0 replies; 3+ messages in thread
From: Bhupinder Thakur @ 2017-06-06 10:04 UTC (permalink / raw)
To: xen-devel; +Cc: Wei Liu, Julien Grall, Stefano Stabellini, Ian Jackson
Xenconsole functions take domain structure as input. These functions shall be
modified to take console structure as input since these functions typically perform
console specific operations.
Also the console specific functions starting with prefix "domain_" shall be modified
to "console_" to indicate that these are console specific functions.
This patch is in preparation to support multiple consoles to support vuart console.
Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
---
Changes since v3:
- The changes in xenconsole have been split into four patches. This is the second patch.
tools/console/daemon/io.c | 82 +++++++++++++++++++++++------------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 0402ddf..c5dd08d 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -163,10 +163,10 @@ static int write_with_timestamp(int fd, const char *data, size_t sz,
return 0;
}
-static void buffer_append(struct domain *dom)
+static void buffer_append(struct console *con)
{
- struct console *con = &dom->console;
struct buffer *buffer = &con->buffer;
+ struct domain *dom = con->d;
XENCONS_RING_IDX cons, prod, size;
struct xencons_interface *intf = con->interface;
@@ -296,12 +296,13 @@ static int create_hv_log(void)
return fd;
}
-static int create_domain_log(struct domain *dom)
+static int create_console_log(struct console *con)
{
char logfile[PATH_MAX];
char *namepath, *data, *s;
int fd;
unsigned int len;
+ struct domain *dom = con->d;
namepath = xs_get_domain_path(xs, dom->domid);
s = realloc(namepath, strlen(namepath) + 6);
@@ -342,10 +343,8 @@ static int create_domain_log(struct domain *dom)
return fd;
}
-static void domain_close_tty(struct domain *dom)
+static void console_close_tty(struct console *con)
{
- struct console *con = &dom->console;
-
if (con->master_fd != -1) {
close(con->master_fd);
con->master_fd = -1;
@@ -417,7 +416,7 @@ void cfmakeraw(struct termios *termios_p)
}
#endif /* __sun__ */
-static int domain_create_tty(struct domain *dom)
+static int console_create_tty(struct console *con)
{
const char *slave;
char *path;
@@ -426,7 +425,7 @@ static int domain_create_tty(struct domain *dom)
char *data;
unsigned int len;
struct termios term;
- struct console *con = &dom->console;
+ struct domain *dom = con->d;
assert(con->slave_fd == -1);
assert(con->master_fd == -1);
@@ -487,7 +486,7 @@ static int domain_create_tty(struct domain *dom)
return 1;
out:
- domain_close_tty(dom);
+ console_close_tty(con);
return 0;
}
@@ -526,10 +525,8 @@ static int xs_gather(struct xs_handle *xs, const char *dir, ...)
return ret;
}
-static void domain_unmap_interface(struct domain *dom)
+static void console_unmap_interface(struct console *con)
{
- struct console *con = &dom->console;
-
if (con->interface == NULL)
return;
if (xgt_handle && con->ring_ref == -1)
@@ -540,11 +537,11 @@ static void domain_unmap_interface(struct domain *dom)
con->ring_ref = -1;
}
-static int domain_create_ring(struct domain *dom)
+static int console_create_ring(struct console *con)
{
int err, remote_port, ring_ref, rc;
char *type, path[PATH_MAX];
- struct console *con = &dom->console;
+ struct domain *dom = con->d;
err = xs_gather(xs, con->conspath,
"ring-ref", "%u", &ring_ref,
@@ -563,7 +560,7 @@ static int domain_create_ring(struct domain *dom)
/* If using ring_ref and it has changed, remap */
if (ring_ref != con->ring_ref && con->ring_ref != -1)
- domain_unmap_interface(dom);
+ console_unmap_interface(con);
if (!con->interface && xgt_handle) {
/* Prefer using grant table */
@@ -621,7 +618,7 @@ static int domain_create_ring(struct domain *dom)
con->remote_port = remote_port;
if (con->master_fd == -1) {
- if (!domain_create_tty(dom)) {
+ if (!console_create_tty(con)) {
err = errno;
xenevtchn_close(dom->xce_handle);
dom->xce_handle = NULL;
@@ -632,7 +629,7 @@ static int domain_create_ring(struct domain *dom)
}
if (log_guest && (con->log_fd == -1))
- con->log_fd = create_domain_log(dom);
+ con->log_fd = create_console_log(con);
out:
return err;
@@ -648,7 +645,7 @@ static bool watch_domain(struct domain *dom, bool watch)
if (watch) {
success = xs_watch(xs, con->conspath, domid_str);
if (success)
- domain_create_ring(dom);
+ console_create_ring(con);
else
xs_unwatch(xs, con->conspath, domid_str);
} else {
@@ -694,6 +691,7 @@ static struct domain *create_domain(int domid)
con->master_pollfd_idx = -1;
con->slave_fd = -1;
con->log_fd = -1;
+ con->d = dom;
dom->xce_pollfd_idx = -1;
dom->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
@@ -746,7 +744,7 @@ static void cleanup_domain(struct domain *d)
{
struct console *con = &d->console;
- domain_close_tty(d);
+ console_close_tty(con);
if (con->log_fd != -1) {
close(con->log_fd);
@@ -764,9 +762,11 @@ static void cleanup_domain(struct domain *d)
static void shutdown_domain(struct domain *d)
{
+ struct console *con = &d->console;
+
d->is_dead = true;
watch_domain(d, false);
- domain_unmap_interface(d);
+ console_unmap_interface(con);
if (d->xce_handle != NULL)
xenevtchn_close(d->xce_handle);
d->xce_handle = NULL;
@@ -797,9 +797,8 @@ static void enum_domains(void)
}
}
-static int ring_free_bytes(struct domain *dom)
+static int ring_free_bytes(struct console *con)
{
- struct console *con = &dom->console;
struct xencons_interface *intf = con->interface;
XENCONS_RING_IDX cons, prod, space;
@@ -814,30 +813,30 @@ static int ring_free_bytes(struct domain *dom)
return (sizeof(intf->in) - space);
}
-static void domain_handle_broken_tty(struct domain *dom, int recreate)
+static void console_handle_broken_tty(struct console *con, int recreate)
{
- domain_close_tty(dom);
+ console_close_tty(con);
if (recreate) {
- domain_create_tty(dom);
+ console_create_tty(con);
} else {
- shutdown_domain(dom);
+ shutdown_domain(con->d);
}
}
-static void handle_tty_read(struct domain *dom)
+static void handle_tty_read(struct console *con)
{
ssize_t len = 0;
char msg[80];
int i;
- struct console *con = &dom->console;
struct xencons_interface *intf = con->interface;
+ struct domain *dom = con->d;
XENCONS_RING_IDX prod;
if (dom->is_dead)
return;
- len = ring_free_bytes(dom);
+ len = ring_free_bytes(con);
if (len == 0)
return;
@@ -851,7 +850,7 @@ static void handle_tty_read(struct domain *dom)
* keep the slave open for the duration.
*/
if (len < 0) {
- domain_handle_broken_tty(dom, domain_is_valid(dom->domid));
+ console_handle_broken_tty(con, domain_is_valid(dom->domid));
} else if (domain_is_valid(dom->domid)) {
prod = intf->in_prod;
for (i = 0; i < len; i++) {
@@ -862,15 +861,15 @@ static void handle_tty_read(struct domain *dom)
intf->in_prod = prod;
xenevtchn_notify(dom->xce_handle, con->local_port);
} else {
- domain_close_tty(dom);
+ console_close_tty(con);
shutdown_domain(dom);
}
}
-static void handle_tty_write(struct domain *dom)
+static void handle_tty_write(struct console *con)
{
ssize_t len;
- struct console *con = &dom->console;
+ struct domain *dom = con->d;
if (dom->is_dead)
return;
@@ -880,7 +879,7 @@ static void handle_tty_write(struct domain *dom)
if (len < 1) {
dolog(LOG_DEBUG, "Write failed on domain %d: %zd, %d\n",
dom->domid, len, errno);
- domain_handle_broken_tty(dom, domain_is_valid(dom->domid));
+ console_handle_broken_tty(con, domain_is_valid(dom->domid));
} else {
buffer_advance(&con->buffer, len);
}
@@ -889,6 +888,7 @@ static void handle_tty_write(struct domain *dom)
static void handle_ring_read(struct domain *dom)
{
xenevtchn_port_or_error_t port;
+ struct console *con = &dom->console;
if (dom->is_dead)
return;
@@ -898,7 +898,7 @@ static void handle_ring_read(struct domain *dom)
dom->event_count++;
- buffer_append(dom);
+ buffer_append(con);
if (dom->event_count < RATE_LIMIT_ALLOWANCE)
(void)xenevtchn_unmask(dom->xce_handle, port);
@@ -922,7 +922,7 @@ static void handle_xs(void)
/* We may get watches firing for domains that have recently
been removed, so dom may be NULL here. */
if (dom && dom->is_dead == false)
- domain_create_ring(dom);
+ console_create_ring(&dom->console);
}
free(vec);
@@ -972,7 +972,7 @@ static void handle_log_reload(void)
if (con->log_fd != -1)
close(con->log_fd);
- con->log_fd = create_domain_log(d);
+ con->log_fd = create_console_log(con);
}
}
@@ -1118,7 +1118,7 @@ void handle_io(void)
if (con->master_fd != -1) {
short events = 0;
- if (!d->is_dead && ring_free_bytes(d))
+ if (!d->is_dead && ring_free_bytes(con))
events |= POLLIN;
if (!buffer_empty(&con->buffer))
@@ -1201,15 +1201,15 @@ void handle_io(void)
if (con->master_fd != -1 && con->master_pollfd_idx != -1) {
if (fds[con->master_pollfd_idx].revents &
~(POLLIN|POLLOUT|POLLPRI))
- domain_handle_broken_tty(d,
+ console_handle_broken_tty(con,
domain_is_valid(d->domid));
else {
if (fds[con->master_pollfd_idx].revents &
POLLIN)
- handle_tty_read(d);
+ handle_tty_read(con);
if (fds[con->master_pollfd_idx].revents &
POLLOUT)
- handle_tty_write(d);
+ handle_tty_write(con);
}
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 00/14 v4] PL011 emulation support in Xen
@ 2017-06-06 17:25 Bhupinder Thakur
2017-06-06 17:25 ` [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input Bhupinder Thakur
0 siblings, 1 reply; 3+ messages in thread
From: Bhupinder Thakur @ 2017-06-06 17:25 UTC (permalink / raw)
To: xen-devel; +Cc: Wei Liu, Julien Grall, Stefano Stabellini, Ian Jackson
PL011 emulation for guests in Xen
===================================
Linaro has published VM System specification for ARM Processors, which
provides a set of guidelines for both guest OS and hypervisor implementations,
such that building OS images according to these guidelines guarantees
that those images can also run on hypervisors compliant with this specification.
One of the spec requirements is that the hypervisor must provide an
emulated PL011 UART as a serial console which meets the minimum requirements in
SBSA UART as defined in appendix B of the following
ARM Server Base Architecture Document:
https://static.docs.arm.com/den0029/a/Server_Base_System_Architecture_v3_1_ARM_DEN_0029A.pdf.
This feature allows the Xen guests to use SBSA compliant pl011 UART as
as a console.
Note that SBSA pl011 UART is a subset of full featured ARM pl011 UART and
supports only a subset of registers as mentioned below. It does not support
rx/tx DMA.
Currently, Xen supports paravirtualized (aka PV console) and an emulated serial
consoles. This feature will expose an emulated SBSA pl011 UART console to the
guest, which a user can access using xenconsole.
The device tree passed to the guest VM will contain the pl011 MMIO address
range and an irq for receiving rx/tx pl011 interrupts. The device tree format
is specified in Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt.
The Xen hypervisor will expose two types of interfaces to the backend and domU.
The interface exposed to domU will be an emulated pl011 UART by emulating the
access to the following pl011 registers by the guest.
- Data register (DR) - RW
- Raw interrupt status register (RIS) - RO
- Masked interrupt status register (MIS)- RO
- Interrupt Mask (IMSC) - RW
- Interrupt Clear (ICR) - WO
It will also inject the pl011 interrupts to the guest in the following
conditions:
- incoming data in the rx buffer for the guest
- there is space in the tx buffer for the guest to write more data
The interface exposed to the backend will be the same PV console interface,
which minimizes the changes required in xenconsole to support a new pl011 console.
This interface has rx and tx ring buffers and an event channel for
sending/receiving events from the backend.
So essentially Xen handles the data on behalf of domU and the backend. Any data
written by domU is captured by Xen and written to the TX (OUT) ring buffer
and a pl011 event is raised to the backend to read the TX ring buffer.
Similarly on reciving a pl011 event, Xen injects an interrupt to guest to
indicate there is data available in the RX (IN) ring buffer.
The pl011 UART state is completely captured in the set of registers
mentioned above and this state is updated everytime there is an event from
the backend or there is register read/write access from domU.
For example, if domU has masked the rx interrupt in the IMSC register, then Xen
will not inject an interrupt to guest and will just update the RIS register.
Once the interrupt is unmasked by guest, the interrupt will be delivered to the
guest.
Changes summary:
Xen Hypervisor
===============
1. Add emulation code to emulate read/write access to pl011 registers and pl011
interrupts:
- It emulates DR read/write by reading and writing from/to the IN and
OUT ring buffers and raising an event to dom0 when there is data in
the OUT ring buffer and injecting an interrupt to the guest when there
is data in the IN ring buffer.
- Other registers are related to interrupt management and essentially
control when interrupts are delivered to the guest.
2. Add a new domctl API to initialize vpl011 emulation in Xen.
3. Enable vpl011 emulation for a domain based on a libxl option passed during
domain creation.
Toolstack
==========
1. Add a new option "vuart" in the domU configuration file to enable/disable vuart.
2. Create a SBSA UART DT node in the guest device tree. It uses a fixed
vpl011 SPI IRQ number and MMIO address.
3. Call vpl011 init DOMCTL API to enable vpl011 emulation.
5. Add a new vuart xenstore node, which contains:
- ring-ref
- event channel
- buffer limit
- type
Xenconsoled
============
1. Split the domain structure to support multiple consoles.
2. Modify different APIs such as buffer_append() etc. to operate on the
console structure.
3. Add support for handling multiple consoles.
4. Add support for vuart console:
The vpl011 changes available at the following repo:
url: ssh://git@git.linaro.org:/people/bhupinder.thakur/xen.git
branch: vpl011_v4
There are some TBD items which need to be looked at in the future:
1. Currently UEFI firmware logs the output to hvc console only. How can
UEFI firmware be made aware of pl011 console and how it can use it
as a console instead of hvc.
2. Linux seems to have hvc console as the default console i.e. if no
console is specified then it uses hvc as the console. How can an
option be provided in Linux to select either hvc or pl011 as the
default console.
3. ACPI support for pl011 device.
CC: ij
CC: wl
CC: ss
CC: jg
CC: kw
Bhupinder Thakur (14):
xen/arm: vpl011: Move vgic register access functions to vreg.h
xen/arm: vpl011: Define generic vreg_reg* access functions in vreg.h
xen/arm: vpl011: Add pl011 uart emulation in Xen
xen/arm: vpl011: Add support for vuart in libxl
xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart
xen/arm: vpl011: Add a new domctl API to initialize vpl011
xen/arm: vpl011: Add a new vuart node in the xenstore
xen/arm: vpl011: Modify xenconsole to define and use a new console
structure
xen/arm: vpl011: Modify xenconsole functions to take console structure
as input
xen/arm: vpl011: Modify xenconsole to support multiple consoles
xen/arm: vpl011: Add support for vuart console in xenconsole
xen/arm: vpl011: Add a new vuart console type to xenconsole client
xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree
xen/arm: vpl011: Update documentation for vuart console support
config/arm32.mk | 1 +
config/arm64.mk | 1 +
docs/man/xl.cfg.pod.5.in | 9 +
docs/misc/console.txt | 44 ++-
tools/console/Makefile | 4 +-
tools/console/client/main.c | 25 +-
tools/console/daemon/io.c | 544 ++++++++++++++++++++++++-----------
tools/libxc/include/xc_dom.h | 3 +
tools/libxc/include/xenctrl.h | 17 ++
tools/libxc/xc_dom_arm.c | 12 +-
tools/libxc/xc_dom_boot.c | 2 +
tools/libxc/xc_domain.c | 23 ++
tools/libxl/libxl.h | 6 +
tools/libxl/libxl_arch.h | 7 +
tools/libxl/libxl_arm.c | 71 ++++-
tools/libxl/libxl_console.c | 47 +++
tools/libxl/libxl_create.c | 12 +-
tools/libxl/libxl_device.c | 9 +-
tools/libxl/libxl_dom.c | 8 +-
tools/libxl/libxl_internal.h | 7 +
tools/libxl/libxl_types.idl | 7 +
tools/libxl/libxl_types_internal.idl | 1 +
tools/libxl/libxl_x86.c | 8 +
tools/xl/Makefile | 4 +
tools/xl/xl_cmdtable.c | 4 +
tools/xl/xl_console.c | 11 +-
tools/xl/xl_parse.c | 8 +
xen/arch/arm/Kconfig | 5 +
xen/arch/arm/Makefile | 1 +
xen/arch/arm/domain.c | 2 +
xen/arch/arm/domctl.c | 44 ++-
xen/arch/arm/vgic-v2.c | 28 +-
xen/arch/arm/vgic-v3.c | 40 +--
xen/arch/arm/vpl011.c | 418 +++++++++++++++++++++++++++
xen/include/asm-arm/domain.h | 6 +
xen/include/asm-arm/pl011-uart.h | 2 +
xen/include/asm-arm/vgic.h | 111 +------
xen/include/asm-arm/vpl011.h | 74 +++++
xen/include/asm-arm/vreg.h | 109 +++++++
xen/include/public/arch-arm.h | 6 +
xen/include/public/domctl.h | 12 +
xen/include/public/io/console.h | 4 +
42 files changed, 1421 insertions(+), 336 deletions(-)
create mode 100644 xen/arch/arm/vpl011.c
create mode 100644 xen/include/asm-arm/vpl011.h
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input
2017-06-06 17:25 [PATCH 00/14 v4] PL011 emulation support in Xen Bhupinder Thakur
@ 2017-06-06 17:25 ` Bhupinder Thakur
2017-06-07 0:43 ` Stefano Stabellini
0 siblings, 1 reply; 3+ messages in thread
From: Bhupinder Thakur @ 2017-06-06 17:25 UTC (permalink / raw)
To: xen-devel; +Cc: Wei Liu, Julien Grall, Stefano Stabellini, Ian Jackson
Xenconsole functions take domain structure as input. These functions shall be
modified to take console structure as input since these functions typically perform
console specific operations.
Also the console specific functions starting with prefix "domain_" shall be modified
to "console_" to indicate that these are console specific functions.
This patch is in preparation to support multiple consoles to support vuart console.
Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
---
CC: ij
CC: wl
CC: ss
CC: jg
Changes since v3:
- The changes in xenconsole have been split into four patches. This is the second patch.
tools/console/daemon/io.c | 82 +++++++++++++++++++++++------------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 0402ddf..c5dd08d 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -163,10 +163,10 @@ static int write_with_timestamp(int fd, const char *data, size_t sz,
return 0;
}
-static void buffer_append(struct domain *dom)
+static void buffer_append(struct console *con)
{
- struct console *con = &dom->console;
struct buffer *buffer = &con->buffer;
+ struct domain *dom = con->d;
XENCONS_RING_IDX cons, prod, size;
struct xencons_interface *intf = con->interface;
@@ -296,12 +296,13 @@ static int create_hv_log(void)
return fd;
}
-static int create_domain_log(struct domain *dom)
+static int create_console_log(struct console *con)
{
char logfile[PATH_MAX];
char *namepath, *data, *s;
int fd;
unsigned int len;
+ struct domain *dom = con->d;
namepath = xs_get_domain_path(xs, dom->domid);
s = realloc(namepath, strlen(namepath) + 6);
@@ -342,10 +343,8 @@ static int create_domain_log(struct domain *dom)
return fd;
}
-static void domain_close_tty(struct domain *dom)
+static void console_close_tty(struct console *con)
{
- struct console *con = &dom->console;
-
if (con->master_fd != -1) {
close(con->master_fd);
con->master_fd = -1;
@@ -417,7 +416,7 @@ void cfmakeraw(struct termios *termios_p)
}
#endif /* __sun__ */
-static int domain_create_tty(struct domain *dom)
+static int console_create_tty(struct console *con)
{
const char *slave;
char *path;
@@ -426,7 +425,7 @@ static int domain_create_tty(struct domain *dom)
char *data;
unsigned int len;
struct termios term;
- struct console *con = &dom->console;
+ struct domain *dom = con->d;
assert(con->slave_fd == -1);
assert(con->master_fd == -1);
@@ -487,7 +486,7 @@ static int domain_create_tty(struct domain *dom)
return 1;
out:
- domain_close_tty(dom);
+ console_close_tty(con);
return 0;
}
@@ -526,10 +525,8 @@ static int xs_gather(struct xs_handle *xs, const char *dir, ...)
return ret;
}
-static void domain_unmap_interface(struct domain *dom)
+static void console_unmap_interface(struct console *con)
{
- struct console *con = &dom->console;
-
if (con->interface == NULL)
return;
if (xgt_handle && con->ring_ref == -1)
@@ -540,11 +537,11 @@ static void domain_unmap_interface(struct domain *dom)
con->ring_ref = -1;
}
-static int domain_create_ring(struct domain *dom)
+static int console_create_ring(struct console *con)
{
int err, remote_port, ring_ref, rc;
char *type, path[PATH_MAX];
- struct console *con = &dom->console;
+ struct domain *dom = con->d;
err = xs_gather(xs, con->conspath,
"ring-ref", "%u", &ring_ref,
@@ -563,7 +560,7 @@ static int domain_create_ring(struct domain *dom)
/* If using ring_ref and it has changed, remap */
if (ring_ref != con->ring_ref && con->ring_ref != -1)
- domain_unmap_interface(dom);
+ console_unmap_interface(con);
if (!con->interface && xgt_handle) {
/* Prefer using grant table */
@@ -621,7 +618,7 @@ static int domain_create_ring(struct domain *dom)
con->remote_port = remote_port;
if (con->master_fd == -1) {
- if (!domain_create_tty(dom)) {
+ if (!console_create_tty(con)) {
err = errno;
xenevtchn_close(dom->xce_handle);
dom->xce_handle = NULL;
@@ -632,7 +629,7 @@ static int domain_create_ring(struct domain *dom)
}
if (log_guest && (con->log_fd == -1))
- con->log_fd = create_domain_log(dom);
+ con->log_fd = create_console_log(con);
out:
return err;
@@ -648,7 +645,7 @@ static bool watch_domain(struct domain *dom, bool watch)
if (watch) {
success = xs_watch(xs, con->conspath, domid_str);
if (success)
- domain_create_ring(dom);
+ console_create_ring(con);
else
xs_unwatch(xs, con->conspath, domid_str);
} else {
@@ -694,6 +691,7 @@ static struct domain *create_domain(int domid)
con->master_pollfd_idx = -1;
con->slave_fd = -1;
con->log_fd = -1;
+ con->d = dom;
dom->xce_pollfd_idx = -1;
dom->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
@@ -746,7 +744,7 @@ static void cleanup_domain(struct domain *d)
{
struct console *con = &d->console;
- domain_close_tty(d);
+ console_close_tty(con);
if (con->log_fd != -1) {
close(con->log_fd);
@@ -764,9 +762,11 @@ static void cleanup_domain(struct domain *d)
static void shutdown_domain(struct domain *d)
{
+ struct console *con = &d->console;
+
d->is_dead = true;
watch_domain(d, false);
- domain_unmap_interface(d);
+ console_unmap_interface(con);
if (d->xce_handle != NULL)
xenevtchn_close(d->xce_handle);
d->xce_handle = NULL;
@@ -797,9 +797,8 @@ static void enum_domains(void)
}
}
-static int ring_free_bytes(struct domain *dom)
+static int ring_free_bytes(struct console *con)
{
- struct console *con = &dom->console;
struct xencons_interface *intf = con->interface;
XENCONS_RING_IDX cons, prod, space;
@@ -814,30 +813,30 @@ static int ring_free_bytes(struct domain *dom)
return (sizeof(intf->in) - space);
}
-static void domain_handle_broken_tty(struct domain *dom, int recreate)
+static void console_handle_broken_tty(struct console *con, int recreate)
{
- domain_close_tty(dom);
+ console_close_tty(con);
if (recreate) {
- domain_create_tty(dom);
+ console_create_tty(con);
} else {
- shutdown_domain(dom);
+ shutdown_domain(con->d);
}
}
-static void handle_tty_read(struct domain *dom)
+static void handle_tty_read(struct console *con)
{
ssize_t len = 0;
char msg[80];
int i;
- struct console *con = &dom->console;
struct xencons_interface *intf = con->interface;
+ struct domain *dom = con->d;
XENCONS_RING_IDX prod;
if (dom->is_dead)
return;
- len = ring_free_bytes(dom);
+ len = ring_free_bytes(con);
if (len == 0)
return;
@@ -851,7 +850,7 @@ static void handle_tty_read(struct domain *dom)
* keep the slave open for the duration.
*/
if (len < 0) {
- domain_handle_broken_tty(dom, domain_is_valid(dom->domid));
+ console_handle_broken_tty(con, domain_is_valid(dom->domid));
} else if (domain_is_valid(dom->domid)) {
prod = intf->in_prod;
for (i = 0; i < len; i++) {
@@ -862,15 +861,15 @@ static void handle_tty_read(struct domain *dom)
intf->in_prod = prod;
xenevtchn_notify(dom->xce_handle, con->local_port);
} else {
- domain_close_tty(dom);
+ console_close_tty(con);
shutdown_domain(dom);
}
}
-static void handle_tty_write(struct domain *dom)
+static void handle_tty_write(struct console *con)
{
ssize_t len;
- struct console *con = &dom->console;
+ struct domain *dom = con->d;
if (dom->is_dead)
return;
@@ -880,7 +879,7 @@ static void handle_tty_write(struct domain *dom)
if (len < 1) {
dolog(LOG_DEBUG, "Write failed on domain %d: %zd, %d\n",
dom->domid, len, errno);
- domain_handle_broken_tty(dom, domain_is_valid(dom->domid));
+ console_handle_broken_tty(con, domain_is_valid(dom->domid));
} else {
buffer_advance(&con->buffer, len);
}
@@ -889,6 +888,7 @@ static void handle_tty_write(struct domain *dom)
static void handle_ring_read(struct domain *dom)
{
xenevtchn_port_or_error_t port;
+ struct console *con = &dom->console;
if (dom->is_dead)
return;
@@ -898,7 +898,7 @@ static void handle_ring_read(struct domain *dom)
dom->event_count++;
- buffer_append(dom);
+ buffer_append(con);
if (dom->event_count < RATE_LIMIT_ALLOWANCE)
(void)xenevtchn_unmask(dom->xce_handle, port);
@@ -922,7 +922,7 @@ static void handle_xs(void)
/* We may get watches firing for domains that have recently
been removed, so dom may be NULL here. */
if (dom && dom->is_dead == false)
- domain_create_ring(dom);
+ console_create_ring(&dom->console);
}
free(vec);
@@ -972,7 +972,7 @@ static void handle_log_reload(void)
if (con->log_fd != -1)
close(con->log_fd);
- con->log_fd = create_domain_log(d);
+ con->log_fd = create_console_log(con);
}
}
@@ -1118,7 +1118,7 @@ void handle_io(void)
if (con->master_fd != -1) {
short events = 0;
- if (!d->is_dead && ring_free_bytes(d))
+ if (!d->is_dead && ring_free_bytes(con))
events |= POLLIN;
if (!buffer_empty(&con->buffer))
@@ -1201,15 +1201,15 @@ void handle_io(void)
if (con->master_fd != -1 && con->master_pollfd_idx != -1) {
if (fds[con->master_pollfd_idx].revents &
~(POLLIN|POLLOUT|POLLPRI))
- domain_handle_broken_tty(d,
+ console_handle_broken_tty(con,
domain_is_valid(d->domid));
else {
if (fds[con->master_pollfd_idx].revents &
POLLIN)
- handle_tty_read(d);
+ handle_tty_read(con);
if (fds[con->master_pollfd_idx].revents &
POLLOUT)
- handle_tty_write(d);
+ handle_tty_write(con);
}
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input
2017-06-06 17:25 ` [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input Bhupinder Thakur
@ 2017-06-07 0:43 ` Stefano Stabellini
0 siblings, 0 replies; 3+ messages in thread
From: Stefano Stabellini @ 2017-06-07 0:43 UTC (permalink / raw)
To: Bhupinder Thakur
Cc: xen-devel, Julien Grall, Stefano Stabellini, Ian Jackson, Wei Liu
On Tue, 6 Jun 2017, Bhupinder Thakur wrote:
> Xenconsole functions take domain structure as input. These functions shall be
> modified to take console structure as input since these functions typically perform
> console specific operations.
>
> Also the console specific functions starting with prefix "domain_" shall be modified
> to "console_" to indicate that these are console specific functions.
>
> This patch is in preparation to support multiple consoles to support vuart console.
>
> Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> CC: ij
> CC: wl
> CC: ss
> CC: jg
>
> Changes since v3:
> - The changes in xenconsole have been split into four patches. This is the second patch.
>
> tools/console/daemon/io.c | 82 +++++++++++++++++++++++------------------------
> 1 file changed, 41 insertions(+), 41 deletions(-)
>
> diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
> index 0402ddf..c5dd08d 100644
> --- a/tools/console/daemon/io.c
> +++ b/tools/console/daemon/io.c
> @@ -163,10 +163,10 @@ static int write_with_timestamp(int fd, const char *data, size_t sz,
> return 0;
> }
>
> -static void buffer_append(struct domain *dom)
> +static void buffer_append(struct console *con)
> {
> - struct console *con = &dom->console;
> struct buffer *buffer = &con->buffer;
> + struct domain *dom = con->d;
> XENCONS_RING_IDX cons, prod, size;
> struct xencons_interface *intf = con->interface;
>
> @@ -296,12 +296,13 @@ static int create_hv_log(void)
> return fd;
> }
>
> -static int create_domain_log(struct domain *dom)
> +static int create_console_log(struct console *con)
> {
> char logfile[PATH_MAX];
> char *namepath, *data, *s;
> int fd;
> unsigned int len;
> + struct domain *dom = con->d;
>
> namepath = xs_get_domain_path(xs, dom->domid);
> s = realloc(namepath, strlen(namepath) + 6);
> @@ -342,10 +343,8 @@ static int create_domain_log(struct domain *dom)
> return fd;
> }
>
> -static void domain_close_tty(struct domain *dom)
> +static void console_close_tty(struct console *con)
> {
> - struct console *con = &dom->console;
> -
> if (con->master_fd != -1) {
> close(con->master_fd);
> con->master_fd = -1;
> @@ -417,7 +416,7 @@ void cfmakeraw(struct termios *termios_p)
> }
> #endif /* __sun__ */
>
> -static int domain_create_tty(struct domain *dom)
> +static int console_create_tty(struct console *con)
> {
> const char *slave;
> char *path;
> @@ -426,7 +425,7 @@ static int domain_create_tty(struct domain *dom)
> char *data;
> unsigned int len;
> struct termios term;
> - struct console *con = &dom->console;
> + struct domain *dom = con->d;
>
> assert(con->slave_fd == -1);
> assert(con->master_fd == -1);
> @@ -487,7 +486,7 @@ static int domain_create_tty(struct domain *dom)
>
> return 1;
> out:
> - domain_close_tty(dom);
> + console_close_tty(con);
> return 0;
> }
>
> @@ -526,10 +525,8 @@ static int xs_gather(struct xs_handle *xs, const char *dir, ...)
> return ret;
> }
>
> -static void domain_unmap_interface(struct domain *dom)
> +static void console_unmap_interface(struct console *con)
> {
> - struct console *con = &dom->console;
> -
> if (con->interface == NULL)
> return;
> if (xgt_handle && con->ring_ref == -1)
> @@ -540,11 +537,11 @@ static void domain_unmap_interface(struct domain *dom)
> con->ring_ref = -1;
> }
>
> -static int domain_create_ring(struct domain *dom)
> +static int console_create_ring(struct console *con)
> {
> int err, remote_port, ring_ref, rc;
> char *type, path[PATH_MAX];
> - struct console *con = &dom->console;
> + struct domain *dom = con->d;
>
> err = xs_gather(xs, con->conspath,
> "ring-ref", "%u", &ring_ref,
> @@ -563,7 +560,7 @@ static int domain_create_ring(struct domain *dom)
>
> /* If using ring_ref and it has changed, remap */
> if (ring_ref != con->ring_ref && con->ring_ref != -1)
> - domain_unmap_interface(dom);
> + console_unmap_interface(con);
>
> if (!con->interface && xgt_handle) {
> /* Prefer using grant table */
> @@ -621,7 +618,7 @@ static int domain_create_ring(struct domain *dom)
> con->remote_port = remote_port;
>
> if (con->master_fd == -1) {
> - if (!domain_create_tty(dom)) {
> + if (!console_create_tty(con)) {
> err = errno;
> xenevtchn_close(dom->xce_handle);
> dom->xce_handle = NULL;
> @@ -632,7 +629,7 @@ static int domain_create_ring(struct domain *dom)
> }
>
> if (log_guest && (con->log_fd == -1))
> - con->log_fd = create_domain_log(dom);
> + con->log_fd = create_console_log(con);
>
> out:
> return err;
> @@ -648,7 +645,7 @@ static bool watch_domain(struct domain *dom, bool watch)
> if (watch) {
> success = xs_watch(xs, con->conspath, domid_str);
> if (success)
> - domain_create_ring(dom);
> + console_create_ring(con);
> else
> xs_unwatch(xs, con->conspath, domid_str);
> } else {
> @@ -694,6 +691,7 @@ static struct domain *create_domain(int domid)
> con->master_pollfd_idx = -1;
> con->slave_fd = -1;
> con->log_fd = -1;
> + con->d = dom;
> dom->xce_pollfd_idx = -1;
>
> dom->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
> @@ -746,7 +744,7 @@ static void cleanup_domain(struct domain *d)
> {
> struct console *con = &d->console;
>
> - domain_close_tty(d);
> + console_close_tty(con);
>
> if (con->log_fd != -1) {
> close(con->log_fd);
> @@ -764,9 +762,11 @@ static void cleanup_domain(struct domain *d)
>
> static void shutdown_domain(struct domain *d)
> {
> + struct console *con = &d->console;
> +
> d->is_dead = true;
> watch_domain(d, false);
> - domain_unmap_interface(d);
> + console_unmap_interface(con);
> if (d->xce_handle != NULL)
> xenevtchn_close(d->xce_handle);
> d->xce_handle = NULL;
> @@ -797,9 +797,8 @@ static void enum_domains(void)
> }
> }
>
> -static int ring_free_bytes(struct domain *dom)
> +static int ring_free_bytes(struct console *con)
> {
> - struct console *con = &dom->console;
> struct xencons_interface *intf = con->interface;
> XENCONS_RING_IDX cons, prod, space;
>
> @@ -814,30 +813,30 @@ static int ring_free_bytes(struct domain *dom)
> return (sizeof(intf->in) - space);
> }
>
> -static void domain_handle_broken_tty(struct domain *dom, int recreate)
> +static void console_handle_broken_tty(struct console *con, int recreate)
> {
> - domain_close_tty(dom);
> + console_close_tty(con);
>
> if (recreate) {
> - domain_create_tty(dom);
> + console_create_tty(con);
> } else {
> - shutdown_domain(dom);
> + shutdown_domain(con->d);
> }
> }
>
> -static void handle_tty_read(struct domain *dom)
> +static void handle_tty_read(struct console *con)
> {
> ssize_t len = 0;
> char msg[80];
> int i;
> - struct console *con = &dom->console;
> struct xencons_interface *intf = con->interface;
> + struct domain *dom = con->d;
> XENCONS_RING_IDX prod;
>
> if (dom->is_dead)
> return;
>
> - len = ring_free_bytes(dom);
> + len = ring_free_bytes(con);
> if (len == 0)
> return;
>
> @@ -851,7 +850,7 @@ static void handle_tty_read(struct domain *dom)
> * keep the slave open for the duration.
> */
> if (len < 0) {
> - domain_handle_broken_tty(dom, domain_is_valid(dom->domid));
> + console_handle_broken_tty(con, domain_is_valid(dom->domid));
> } else if (domain_is_valid(dom->domid)) {
> prod = intf->in_prod;
> for (i = 0; i < len; i++) {
> @@ -862,15 +861,15 @@ static void handle_tty_read(struct domain *dom)
> intf->in_prod = prod;
> xenevtchn_notify(dom->xce_handle, con->local_port);
> } else {
> - domain_close_tty(dom);
> + console_close_tty(con);
> shutdown_domain(dom);
> }
> }
>
> -static void handle_tty_write(struct domain *dom)
> +static void handle_tty_write(struct console *con)
> {
> ssize_t len;
> - struct console *con = &dom->console;
> + struct domain *dom = con->d;
>
> if (dom->is_dead)
> return;
> @@ -880,7 +879,7 @@ static void handle_tty_write(struct domain *dom)
> if (len < 1) {
> dolog(LOG_DEBUG, "Write failed on domain %d: %zd, %d\n",
> dom->domid, len, errno);
> - domain_handle_broken_tty(dom, domain_is_valid(dom->domid));
> + console_handle_broken_tty(con, domain_is_valid(dom->domid));
> } else {
> buffer_advance(&con->buffer, len);
> }
> @@ -889,6 +888,7 @@ static void handle_tty_write(struct domain *dom)
> static void handle_ring_read(struct domain *dom)
> {
> xenevtchn_port_or_error_t port;
> + struct console *con = &dom->console;
>
> if (dom->is_dead)
> return;
> @@ -898,7 +898,7 @@ static void handle_ring_read(struct domain *dom)
>
> dom->event_count++;
>
> - buffer_append(dom);
> + buffer_append(con);
>
> if (dom->event_count < RATE_LIMIT_ALLOWANCE)
> (void)xenevtchn_unmask(dom->xce_handle, port);
> @@ -922,7 +922,7 @@ static void handle_xs(void)
> /* We may get watches firing for domains that have recently
> been removed, so dom may be NULL here. */
> if (dom && dom->is_dead == false)
> - domain_create_ring(dom);
> + console_create_ring(&dom->console);
> }
>
> free(vec);
> @@ -972,7 +972,7 @@ static void handle_log_reload(void)
>
> if (con->log_fd != -1)
> close(con->log_fd);
> - con->log_fd = create_domain_log(d);
> + con->log_fd = create_console_log(con);
> }
> }
>
> @@ -1118,7 +1118,7 @@ void handle_io(void)
>
> if (con->master_fd != -1) {
> short events = 0;
> - if (!d->is_dead && ring_free_bytes(d))
> + if (!d->is_dead && ring_free_bytes(con))
> events |= POLLIN;
>
> if (!buffer_empty(&con->buffer))
> @@ -1201,15 +1201,15 @@ void handle_io(void)
> if (con->master_fd != -1 && con->master_pollfd_idx != -1) {
> if (fds[con->master_pollfd_idx].revents &
> ~(POLLIN|POLLOUT|POLLPRI))
> - domain_handle_broken_tty(d,
> + console_handle_broken_tty(con,
> domain_is_valid(d->domid));
> else {
> if (fds[con->master_pollfd_idx].revents &
> POLLIN)
> - handle_tty_read(d);
> + handle_tty_read(con);
> if (fds[con->master_pollfd_idx].revents &
> POLLOUT)
> - handle_tty_write(d);
> + handle_tty_write(con);
> }
> }
>
> --
> 2.7.4
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-07 0:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-06 10:04 [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input Bhupinder Thakur
-- strict thread matches above, loose matches on Subject: below --
2017-06-06 17:25 [PATCH 00/14 v4] PL011 emulation support in Xen Bhupinder Thakur
2017-06-06 17:25 ` [PATCH 09/14 v4] xen/arm: vpl011: Modify xenconsole functions to take console structure as input Bhupinder Thakur
2017-06-07 0:43 ` Stefano Stabellini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).