Lines Matching +full:max +full:- +full:len
29 #include "chardev/char-fe.h"
30 #include "hw/xen/xen-backend.h"
31 #include "hw/xen/xen-bus-helper.h"
32 #include "hw/qdev-properties.h"
33 #include "hw/qdev-properties-system.h"
61 #define TYPE_XEN_CONSOLE_DEVICE "xen-console"
66 struct buffer *buffer = &con->buffer; in OBJECT_DECLARE_SIMPLE_TYPE()
68 struct xencons_interface *intf = con->sring; in OBJECT_DECLARE_SIMPLE_TYPE()
70 cons = intf->out_cons; in OBJECT_DECLARE_SIMPLE_TYPE()
71 prod = intf->out_prod; in OBJECT_DECLARE_SIMPLE_TYPE()
74 size = prod - cons; in OBJECT_DECLARE_SIMPLE_TYPE()
75 if ((size == 0) || (size > sizeof(intf->out))) in OBJECT_DECLARE_SIMPLE_TYPE()
78 if ((buffer->capacity - buffer->size) < size) { in OBJECT_DECLARE_SIMPLE_TYPE()
79 buffer->capacity += (size + 1024); in OBJECT_DECLARE_SIMPLE_TYPE()
80 buffer->data = g_realloc(buffer->data, buffer->capacity); in OBJECT_DECLARE_SIMPLE_TYPE()
84 buffer->data[buffer->size++] = intf->out[ in OBJECT_DECLARE_SIMPLE_TYPE()
85 MASK_XENCONS_IDX(cons++, intf->out)]; in OBJECT_DECLARE_SIMPLE_TYPE()
88 intf->out_cons = cons; in OBJECT_DECLARE_SIMPLE_TYPE()
89 xen_device_notify_event_channel(XEN_DEVICE(con), con->event_channel, NULL); in OBJECT_DECLARE_SIMPLE_TYPE()
91 if (buffer->max_capacity && in OBJECT_DECLARE_SIMPLE_TYPE()
92 buffer->size > buffer->max_capacity) { in OBJECT_DECLARE_SIMPLE_TYPE()
95 size_t over = buffer->size - buffer->max_capacity; in OBJECT_DECLARE_SIMPLE_TYPE()
96 uint8_t *maxpos = buffer->data + buffer->max_capacity; in OBJECT_DECLARE_SIMPLE_TYPE()
98 memmove(maxpos - over, maxpos, over); in OBJECT_DECLARE_SIMPLE_TYPE()
99 buffer->data = g_realloc(buffer->data, buffer->max_capacity); in OBJECT_DECLARE_SIMPLE_TYPE()
100 buffer->size = buffer->capacity = buffer->max_capacity; in OBJECT_DECLARE_SIMPLE_TYPE()
102 if (buffer->consumed > buffer->max_capacity - over) in OBJECT_DECLARE_SIMPLE_TYPE()
103 buffer->consumed = buffer->max_capacity - over; in OBJECT_DECLARE_SIMPLE_TYPE()
108 static void buffer_advance(struct buffer *buffer, size_t len) in buffer_advance() argument
110 buffer->consumed += len; in buffer_advance()
111 if (buffer->consumed == buffer->size) { in buffer_advance()
112 buffer->consumed = 0; in buffer_advance()
113 buffer->size = 0; in buffer_advance()
119 struct xencons_interface *intf = con->sring; in ring_free_bytes()
122 cons = intf->in_cons; in ring_free_bytes()
123 prod = intf->in_prod; in ring_free_bytes()
126 space = prod - cons; in ring_free_bytes()
127 if (space > sizeof(intf->in)) in ring_free_bytes()
130 return (sizeof(intf->in) - space); in ring_free_bytes()
139 static void xencons_receive(void *opaque, const uint8_t *buf, int len) in xencons_receive() argument
142 struct xencons_interface *intf = con->sring; in xencons_receive()
144 int i, max; in xencons_receive() local
146 max = ring_free_bytes(con); in xencons_receive()
148 if (max < len) in xencons_receive()
149 len = max; in xencons_receive()
151 prod = intf->in_prod; in xencons_receive()
152 for (i = 0; i < len; i++) { in xencons_receive()
153 intf->in[MASK_XENCONS_IDX(prod++, intf->in)] = in xencons_receive()
157 intf->in_prod = prod; in xencons_receive()
158 xen_device_notify_event_channel(XEN_DEVICE(con), con->event_channel, NULL); in xencons_receive()
163 ssize_t len, size; in xencons_send() local
165 size = con->buffer.size - con->buffer.consumed; in xencons_send()
166 if (qemu_chr_fe_backend_connected(&con->chr)) { in xencons_send()
167 len = qemu_chr_fe_write(&con->chr, in xencons_send()
168 con->buffer.data + con->buffer.consumed, in xencons_send()
171 len = size; in xencons_send()
173 if (len < 1) { in xencons_send()
174 if (!con->backlog) { in xencons_send()
175 con->backlog = 1; in xencons_send()
178 buffer_advance(&con->buffer, len); in xencons_send()
179 if (con->backlog && len == size) { in xencons_send()
180 con->backlog = 0; in xencons_send()
183 return len > 0; in xencons_send()
186 /* -------------------------------------------------------------------- */
193 if (xen_device_backend_get_state(&con->xendev) != XenbusStateConnected) { in con_event()
199 if (con->buffer.size - con->buffer.consumed) { in con_event()
205 /* -------------------------------------------------------------------- */
213 if (xen_device_frontend_scanf(xendev, "ring-ref", "%u", in xen_console_connect()
214 &con->ring_ref) != 1) { in xen_console_connect()
215 error_setg(errp, "failed to read ring-ref"); in xen_console_connect()
225 con->buffer.max_capacity = limit; in xen_console_connect()
228 con->event_channel = xen_device_bind_event_channel(xendev, port, in xen_console_connect()
232 if (!con->event_channel) { in xen_console_connect()
236 switch (con->dev) { in xen_console_connect()
239 * The primary console is special. For real Xen the ring-ref is in xen_console_connect()
243 xen_pfn_t mfn = (xen_pfn_t)con->ring_ref; in xen_console_connect()
244 con->sring = qemu_xen_foreignmem_map(xendev->frontend_id, NULL, in xen_console_connect()
247 if (!con->sring) { in xen_console_connect()
255 * For Xen emulation, we still follow the convention of ring-ref in xen_console_connect()
259 * the guest-side page and event channel also needs to be informed in xen_console_connect()
264 xen_event_channel_get_local_port(con->event_channel)); in xen_console_connect()
265 con->ring_ref = GNTTAB_RESERVED_CONSOLE; in xen_console_connect()
268 con->sring = xen_device_map_grant_refs(xendev, in xen_console_connect()
269 &con->ring_ref, 1, in xen_console_connect()
272 if (!con->sring) { in xen_console_connect()
279 trace_xen_console_connect(con->dev, con->ring_ref, port, in xen_console_connect()
280 con->buffer.max_capacity); in xen_console_connect()
282 qemu_chr_fe_set_handlers(&con->chr, xencons_can_receive, in xen_console_connect()
292 trace_xen_console_disconnect(con->dev); in xen_console_disconnect()
294 qemu_chr_fe_set_handlers(&con->chr, NULL, NULL, NULL, NULL, in xen_console_disconnect()
297 if (con->event_channel) { in xen_console_disconnect()
298 xen_device_unbind_event_channel(xendev, con->event_channel, in xen_console_disconnect()
300 con->event_channel = NULL; in xen_console_disconnect()
302 if (xen_mode == XEN_EMULATE && !con->dev) { in xen_console_disconnect()
307 if (con->sring) { in xen_console_disconnect()
308 if (!con->dev && xen_mode != XEN_EMULATE) { in xen_console_disconnect()
309 qemu_xen_foreignmem_unmap(con->sring, 1); in xen_console_disconnect()
311 xen_device_unmap_grant_refs(xendev, con->sring, in xen_console_disconnect()
312 &con->ring_ref, 1, errp); in xen_console_disconnect()
314 con->sring = NULL; in xen_console_disconnect()
368 if (con->dev == -1) { in xen_console_get_name()
377 value = xs_node_read(xenbus->xsh, XBT_NULL, NULL, &local_err, in xen_console_get_name()
379 xendev->frontend_id); in xen_console_get_name()
381 value = xs_node_read(xenbus->xsh, XBT_NULL, NULL, &local_err, in xen_console_get_name()
383 xendev->frontend_id, idx); in xen_console_get_name()
387 con->dev = idx; in xen_console_get_name()
401 return g_strdup_printf("%u", con->dev); in xen_console_get_name()
408 trace_xen_console_unrealize(con->dev); in xen_console_unrealize()
413 qemu_chr_fe_deinit(&con->chr, false); in xen_console_unrealize()
420 Chardev *cs = qemu_chr_fe_get_driver(&con->chr); in xen_console_realize()
428 if (con->dev == -1) { in xen_console_realize()
434 * The Xen primary console is special. The ring-ref is actually a GFN to in xen_console_realize()
441 if (!con->dev) { in xen_console_realize()
444 } else if (xen_device_frontend_scanf(xendev, "ring-ref", "%u", &u) in xen_console_realize()
452 trace_xen_console_realize(con->dev, object_get_typename(OBJECT(cs))); in xen_console_realize()
456 xen_device_frontend_printf(xendev, "tty", "%s", cs->filename + 4); in xen_console_realize()
460 if (!con->dev && xen_mode != XEN_EMULATE) { in xen_console_realize()
480 char *ret = console_frontend_path(xenbus->xsh, xendev->frontend_id, in xen_console_get_frontend_path()
481 con->dev); in xen_console_get_frontend_path()
492 DEFINE_PROP_INT32("idx", XenConsole, dev, -1),
500 xendev_class->backend = "console"; in xen_console_class_init()
501 xendev_class->device = "console"; in xen_console_class_init()
502 xendev_class->get_name = xen_console_get_name; in xen_console_class_init()
503 xendev_class->realize = xen_console_realize; in xen_console_class_init()
504 xendev_class->frontend_changed = xen_console_frontend_changed; in xen_console_class_init()
505 xendev_class->unrealize = xen_console_unrealize; in xen_console_class_init()
506 xendev_class->get_frontend_path = xen_console_get_frontend_path; in xen_console_class_init()
538 struct qemu_xs_handle *xsh = xenbus->xsh; in type_init()
568 con->dev = number; in type_init()
608 if (!qemu_chr_fe_init(&con->chr, cd, errp)) { in type_init()
638 trace_xen_console_device_destroy(con->dev); in xen_console_device_destroy()