xref: /illumos-gate/usr/src/cmd/bhyve/console.c (revision 32640292339b07090f10ce34d455f98711077343)
1bf21cd93STycho Nightingale /*-
2*32640292SAndy Fiddaman  * SPDX-License-Identifier: BSD-2-Clause
34c87aefeSPatrick Mooney  *
4bf21cd93STycho Nightingale  * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
5bf21cd93STycho Nightingale  * All rights reserved.
6bf21cd93STycho Nightingale  *
7bf21cd93STycho Nightingale  * Redistribution and use in source and binary forms, with or without
8bf21cd93STycho Nightingale  * modification, are permitted provided that the following conditions
9bf21cd93STycho Nightingale  * are met:
10bf21cd93STycho Nightingale  * 1. Redistributions of source code must retain the above copyright
11bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer.
12bf21cd93STycho Nightingale  * 2. Redistributions in binary form must reproduce the above copyright
13bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer in the
14bf21cd93STycho Nightingale  *    documentation and/or other materials provided with the distribution.
15bf21cd93STycho Nightingale  *
16bf21cd93STycho Nightingale  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
17bf21cd93STycho Nightingale  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bf21cd93STycho Nightingale  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19bf21cd93STycho Nightingale  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20bf21cd93STycho Nightingale  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21bf21cd93STycho Nightingale  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22bf21cd93STycho Nightingale  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23bf21cd93STycho Nightingale  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24bf21cd93STycho Nightingale  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25bf21cd93STycho Nightingale  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26bf21cd93STycho Nightingale  * SUCH DAMAGE.
27bf21cd93STycho Nightingale  */
28bf21cd93STycho Nightingale 
29bf21cd93STycho Nightingale #include <sys/cdefs.h>
30bf21cd93STycho Nightingale 
31bf21cd93STycho Nightingale #include <sys/types.h>
32bf21cd93STycho Nightingale 
33bf21cd93STycho Nightingale #include "bhyvegc.h"
34bf21cd93STycho Nightingale #include "console.h"
35bf21cd93STycho Nightingale 
36bf21cd93STycho Nightingale static struct {
37bf21cd93STycho Nightingale 	struct bhyvegc		*gc;
38bf21cd93STycho Nightingale 
39bf21cd93STycho Nightingale 	fb_render_func_t	fb_render_cb;
40bf21cd93STycho Nightingale 	void			*fb_arg;
41bf21cd93STycho Nightingale 
42bf21cd93STycho Nightingale 	kbd_event_func_t	kbd_event_cb;
43bf21cd93STycho Nightingale 	void			*kbd_arg;
444c87aefeSPatrick Mooney 	int			kbd_priority;
45bf21cd93STycho Nightingale 
46bf21cd93STycho Nightingale 	ptr_event_func_t	ptr_event_cb;
47bf21cd93STycho Nightingale 	void			*ptr_arg;
484c87aefeSPatrick Mooney 	int			ptr_priority;
49bf21cd93STycho Nightingale } console;
50bf21cd93STycho Nightingale 
51bf21cd93STycho Nightingale void
console_init(int w,int h,void * fbaddr)524c87aefeSPatrick Mooney console_init(int w, int h, void *fbaddr)
53bf21cd93STycho Nightingale {
544c87aefeSPatrick Mooney 	console.gc = bhyvegc_init(w, h, fbaddr);
554c87aefeSPatrick Mooney }
564c87aefeSPatrick Mooney 
574c87aefeSPatrick Mooney void
console_set_fbaddr(void * fbaddr)584c87aefeSPatrick Mooney console_set_fbaddr(void *fbaddr)
594c87aefeSPatrick Mooney {
604c87aefeSPatrick Mooney 	bhyvegc_set_fbaddr(console.gc, fbaddr);
61bf21cd93STycho Nightingale }
62bf21cd93STycho Nightingale 
63bf21cd93STycho Nightingale struct bhyvegc_image *
console_get_image(void)64bf21cd93STycho Nightingale console_get_image(void)
65bf21cd93STycho Nightingale {
66bf21cd93STycho Nightingale 	struct bhyvegc_image *bhyvegc_image;
67bf21cd93STycho Nightingale 
68bf21cd93STycho Nightingale 	bhyvegc_image = bhyvegc_get_image(console.gc);
69bf21cd93STycho Nightingale 
70bf21cd93STycho Nightingale 	return (bhyvegc_image);
71bf21cd93STycho Nightingale }
72bf21cd93STycho Nightingale 
73bf21cd93STycho Nightingale void
console_fb_register(fb_render_func_t render_cb,void * arg)74bf21cd93STycho Nightingale console_fb_register(fb_render_func_t render_cb, void *arg)
75bf21cd93STycho Nightingale {
76bf21cd93STycho Nightingale 	console.fb_render_cb = render_cb;
77bf21cd93STycho Nightingale 	console.fb_arg = arg;
78bf21cd93STycho Nightingale }
79bf21cd93STycho Nightingale 
80bf21cd93STycho Nightingale void
console_refresh(void)81bf21cd93STycho Nightingale console_refresh(void)
82bf21cd93STycho Nightingale {
834c87aefeSPatrick Mooney 	if (console.fb_render_cb)
84bf21cd93STycho Nightingale 		(*console.fb_render_cb)(console.gc, console.fb_arg);
85bf21cd93STycho Nightingale }
86bf21cd93STycho Nightingale 
87bf21cd93STycho Nightingale void
console_kbd_register(kbd_event_func_t event_cb,void * arg,int pri)884c87aefeSPatrick Mooney console_kbd_register(kbd_event_func_t event_cb, void *arg, int pri)
89bf21cd93STycho Nightingale {
904c87aefeSPatrick Mooney 	if (pri > console.kbd_priority) {
91bf21cd93STycho Nightingale 		console.kbd_event_cb = event_cb;
92bf21cd93STycho Nightingale 		console.kbd_arg = arg;
934c87aefeSPatrick Mooney 		console.kbd_priority = pri;
944c87aefeSPatrick Mooney 	}
95bf21cd93STycho Nightingale }
96bf21cd93STycho Nightingale 
97bf21cd93STycho Nightingale void
console_ptr_register(ptr_event_func_t event_cb,void * arg,int pri)984c87aefeSPatrick Mooney console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri)
99bf21cd93STycho Nightingale {
1004c87aefeSPatrick Mooney 	if (pri > console.ptr_priority) {
101bf21cd93STycho Nightingale 		console.ptr_event_cb = event_cb;
102bf21cd93STycho Nightingale 		console.ptr_arg = arg;
1034c87aefeSPatrick Mooney 		console.ptr_priority = pri;
1044c87aefeSPatrick Mooney 	}
105bf21cd93STycho Nightingale }
106bf21cd93STycho Nightingale 
107bf21cd93STycho Nightingale void
console_key_event(int down,uint32_t keysym,uint32_t keycode)108b0de25cbSAndy Fiddaman console_key_event(int down, uint32_t keysym, uint32_t keycode)
109bf21cd93STycho Nightingale {
1104c87aefeSPatrick Mooney 	if (console.kbd_event_cb)
111b0de25cbSAndy Fiddaman 		(*console.kbd_event_cb)(down, keysym, keycode, console.kbd_arg);
112bf21cd93STycho Nightingale }
113bf21cd93STycho Nightingale 
114bf21cd93STycho Nightingale void
console_ptr_event(uint8_t button,int x,int y)115bf21cd93STycho Nightingale console_ptr_event(uint8_t button, int x, int y)
116bf21cd93STycho Nightingale {
1174c87aefeSPatrick Mooney 	if (console.ptr_event_cb)
118bf21cd93STycho Nightingale 		(*console.ptr_event_cb)(button, x, y, console.ptr_arg);
119bf21cd93STycho Nightingale }
120