From: Son Hyunjun Date: Thu, 12 Apr 2012 09:27:36 +0000 (+0900) Subject: [Title] add api to check if hax is available X-Git-Tag: TizenStudio_2.0_p2.3~1514^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a601cbdaec9750cef04dfc303f4b9e982a3d15ab;p=sdk%2Femulator%2Fqemu.git [Title] add api to check if hax is available [Type] Enhancement [Module] Hax [Priority] Minor [CQ#] [Redmine#] [Problem] [Cause] [Solution] Change-Id: Ifab8570872c51547f6256ee339b9c52d5cd2b40e --- diff --git a/tizen/src/Makefile.tizen b/tizen/src/Makefile.tizen index 56c32ec..3d84b14 100755 --- a/tizen/src/Makefile.tizen +++ b/tizen/src/Makefile.tizen @@ -82,6 +82,11 @@ obj-i386-$(CONFIG_WIN32) += maru_camera_win32_pci.o ifdef CONFIG_LINUX # libs for maru camera on linux host LIBS += -lv4l2 -lv4lconvert endif + +ifdef CONFIG_WIN32 +obj-i386-y += check_hax.o +endif + ifdef CONFIG_WIN32 # libs for maru camera on windows host LIBS += -lole32 -loleaut32 -luuid -lstrmiids endif diff --git a/tizen/src/check_hax.c b/tizen/src/check_hax.c new file mode 100755 index 0000000..997b80c --- /dev/null +++ b/tizen/src/check_hax.c @@ -0,0 +1,119 @@ +/* + * check if hax is available. reference:target-i386/hax-all.c + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SeokYeon Hwang + * Hyunjun Son + * YeongKyoon Lee + * + * 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "target-i386/hax-i386.h" +#include "debug_ch.h" +#include "check_hax.h" + +MULTI_DEBUG_CHANNEL(qemu, check_hax); + +/* Current version */ +static uint32_t hax_cur_version = 0x1; +/* Least HAX kernel version */ +static uint32_t hax_lest_version = 0x1; + +static int hax_get_capability( struct hax_state *hax ); +static int hax_version_support( struct hax_state *hax ); + +int check_hax( void ) { + + struct hax_state hax_stat; + memset(&hax_stat, 0, sizeof(struct hax_state)); + + struct hax_state* hax = &hax_stat; + + hax->fd = hax_mod_open(); + + int ret_fd = hax_invalid_fd( hax->fd ); + if ( hax_invalid_fd( hax->fd ) ) { + ERR( "Invalid fd:%d\n", ret_fd ); + return ret_fd; + } else { + TRACE( "Succcess hax_mod_open.\n" ); + } + + int ret_cap = hax_get_capability( hax ); + if ( ret_cap ) { + ERR( "Not capable:%d\n", ret_cap ); + return ret_cap; + } else { + TRACE( "Succcess hax_get_capability.\n" ); + } + + int ret_ver = hax_version_support( hax ); + if ( !ret_ver ) { + ERR( "Incompat Hax version. Qemu current version %x ", hax_cur_version ); + ERR( "requires least HAX version %x\n", hax_lest_version ); + return !ret_ver; + } else { + TRACE( "Succcess hax_version_support.\n" ); + } + + return 0; + +} + +static int hax_get_capability( struct hax_state *hax ) { + int ret; + struct hax_capabilityinfo capinfo, *cap = &capinfo; + + ret = hax_capability( hax, cap ); + if ( ret ) + return ret; + + if ( ( ( cap->wstatus & HAX_CAP_WORKSTATUS_MASK ) == HAX_CAP_STATUS_NOTWORKING ) ) { + if ( cap->winfo & HAX_CAP_FAILREASON_VT ) + dprint( "VTX feature is not enabled. which will cause HAX driver not working.\n" ); + else if ( cap->winfo & HAX_CAP_FAILREASON_NX ) + dprint( "NX feature is not enabled, which will cause HAX driver not working.\n" ); + return -ENXIO; + } + + if ( cap->wstatus & HAX_CAP_MEMQUOTA ) { + if ( cap->mem_quota < hax->mem_quota ) { + dprint( "The memory needed by this VM exceeds the driver limit.\n" ); + return -ENOSPC; + } + } + return 0; +} + +static int hax_version_support( struct hax_state *hax ) { + int ret; + struct hax_module_version version; + + ret = hax_mod_version( hax, &version ); + if ( ret < 0 ) + return 0; + + if ( ( hax_lest_version > version.cur_version ) || ( hax_cur_version < version.compat_version ) ) + return 0; + + return 1; +} diff --git a/tizen/src/check_hax.h b/tizen/src/check_hax.h new file mode 100644 index 0000000..8a67bdd --- /dev/null +++ b/tizen/src/check_hax.h @@ -0,0 +1,38 @@ +/* + * check if hax is available + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SeokYeon Hwang + * Hyunjun Son + * YeongKyoon Lee + * + * 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. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef CHECK_HAX_H_ +#define CHECK_HAX_H_ + +/** + * @return 0:hax is available, others:error code + */ +int check_hax( void ); + +#endif /* CHECK_HAX_H_ */