From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51584 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMRMP-0006YD-4g for qemu-devel@nongnu.org; Wed, 09 Jun 2010 15:54:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OMRMI-0000YN-Bx for qemu-devel@nongnu.org; Wed, 09 Jun 2010 15:54:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21843) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMRMI-0000Y0-1K for qemu-devel@nongnu.org; Wed, 09 Jun 2010 15:54:42 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o59Jsf9L005678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Jun 2010 15:54:41 -0400 Date: Wed, 9 Jun 2010 16:54:36 -0300 From: Luiz Capitulino Subject: Re: [Qemu-devel] [PATCH 08/19] Convert RTC to use enumerations for configuration parameters Message-ID: <20100609165436.2982292c@redhat.com> In-Reply-To: <1275921752-29420-9-git-send-email-berrange@redhat.com> References: <1275921752-29420-1-git-send-email-berrange@redhat.com> <1275921752-29420-9-git-send-email-berrange@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org On Mon, 7 Jun 2010 15:42:21 +0100 "Daniel P. Berrange" wrote: > Convert the rtc clock and driftfix parameters to use enums for > configuration. This ensures strict validation at time of config > parsing. >=20 > Also fixes a bug in qemu-config.c where 'driftfix' was never > enabled because this is a target independant compliation unit, > thus cannot include config-target.h and thus never has the > TARGET_I386 symbol defined. >=20 > Ideally the 'base' parameter would be an enum too, but this > value is overloaded to also accept a pretty-printed start > date. >=20 > Signed-off-by: Daniel P. Berrange > --- > hw/mc146818rtc.c | 8 ++++---- > qemu-config.c | 27 +++++++++++++++++++++++---- > sysemu.h | 20 +++++++++++++++++++- > vl.c | 34 ++++++++++------------------------ > 4 files changed, 56 insertions(+), 33 deletions(-) >=20 > diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c > index c3e6a70..cbb072c 100644 > --- a/hw/mc146818rtc.c > +++ b/hw/mc146818rtc.c > @@ -202,7 +202,7 @@ static void rtc_periodic_timer(void *opaque) > if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { > s->cmos_data[RTC_REG_C] |=3D 0xc0; > #ifdef TARGET_I386 > - if(rtc_td_hack) { > + if(rtc_driftfix =3D=3D QEMU_RTC_DRIFTFIX_SLEW) { > if (s->irq_reinject_on_ack_count >=3D RTC_REINJECT_ON_ACK_CO= UNT) > s->irq_reinject_on_ack_count =3D 0; =09 > apic_reset_irq_delivered(); > @@ -552,7 +552,7 @@ static int rtc_post_load(void *opaque, int version_id) > RTCState *s =3D opaque; > =20 > if (version_id >=3D 2) { > - if (rtc_td_hack) { > + if (rtc_driftfix =3D=3D QEMU_RTC_DRIFTFIX_SLEW) { > rtc_coalesced_timer_update(s); > } > } > @@ -597,7 +597,7 @@ static void rtc_reset(void *opaque) > qemu_irq_lower(s->irq); > =20 > #ifdef TARGET_I386 > - if (rtc_td_hack) > + if (rtc_driftfix =3D=3D QEMU_RTC_DRIFTFIX_SLEW) > s->irq_coalesced =3D 0; > #endif > } > @@ -619,7 +619,7 @@ static int rtc_initfn(ISADevice *dev) > =20 > s->periodic_timer =3D qemu_new_timer(rtc_clock, rtc_periodic_timer, = s); > #ifdef TARGET_I386 > - if (rtc_td_hack) > + if (rtc_driftfix =3D=3D QEMU_RTC_DRIFTFIX_SLEW) > s->coalesced_timer =3D > qemu_new_timer(rtc_clock, rtc_coalesced_timer, s); > #endif > diff --git a/qemu-config.c b/qemu-config.c > index f656e6b..75cddc1 100644 > --- a/qemu-config.c > +++ b/qemu-config.c > @@ -288,6 +288,11 @@ QemuOptsList qemu_net_opts =3D { > }, > }; > =20 > +QEMU_ENUM_IMPL(qemu_rtc_clock, QEMU_RTC_CLOCK_LAST, > + "host", "guest"); > +QEMU_ENUM_IMPL(qemu_rtc_driftfix, QEMU_RTC_DRIFTFIX_LAST, > + "none", "slew"); > + > QemuOptsList qemu_rtc_opts =3D { > .name =3D "rtc", > .head =3D QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), > @@ -297,12 +302,26 @@ QemuOptsList qemu_rtc_opts =3D { > .type =3D QEMU_OPT_STRING, > },{ > .name =3D "clock", > - .type =3D QEMU_OPT_STRING, > -#ifdef TARGET_I386 > + .type =3D QEMU_OPT_ENUM, > + .validate =3D { > + .optEnum =3D { > + .to_string =3D qemu_rtc_clock_to_string, > + .to_string_list =3D qemu_rtc_clock_to_string_list, > + .from_string =3D qemu_rtc_clock_from_string, > + .last =3D QEMU_RTC_CLOCK_LAST, > + }, > + }, > },{ > .name =3D "driftfix", > - .type =3D QEMU_OPT_STRING, > -#endif > + .type =3D QEMU_OPT_ENUM, > + .validate =3D { > + .optEnum =3D { > + .to_string =3D qemu_rtc_driftfix_to_string, > + .to_string_list =3D qemu_rtc_driftfix_to_string_list, > + .from_string =3D qemu_rtc_driftfix_from_string, > + .last =3D QEMU_RTC_DRIFTFIX_LAST, > + }, > + }, > }, > { /* end if list */ } > }, > diff --git a/sysemu.h b/sysemu.h > index f0c5eb8..4d39566 100644 > --- a/sysemu.h > +++ b/sysemu.h > @@ -120,7 +120,6 @@ extern uint8_t irq0override; > extern DisplayType display_type; > extern const char *keyboard_layout; > extern int win2k_install_hack; > -extern int rtc_td_hack; > extern int alt_grab; > extern int ctrl_grab; > extern int usb_enabled; > @@ -133,7 +132,26 @@ extern int no_shutdown; > extern int semihosting_enabled; > extern int old_param; > extern int boot_menu; > + > extern QEMUClock *rtc_clock; > +extern int rtc_driftfix; > + > +enum { > + QEMU_RTC_CLOCK_HOST, > + QEMU_RTC_CLOCK_GUEST, > + > + QEMU_RTC_CLOCK_LAST > +}; > +QEMU_ENUM_DECL(qemu_rtc_clock); > + > +enum { > + QEMU_RTC_DRIFTFIX_NONE, > + QEMU_RTC_DRIFTFIX_SLEW, > + > + QEMU_RTC_DRIFTFIX_LAST > +}; > +QEMU_ENUM_DECL(qemu_rtc_driftfix); > + > =20 > #define MAX_NODES 64 > extern int nb_numa_nodes; > diff --git a/vl.c b/vl.c > index 16491c4..0b38d62 100644 > --- a/vl.c > +++ b/vl.c > @@ -201,7 +201,7 @@ CharDriverState *serial_hds[MAX_SERIAL_PORTS]; > CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; > CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; > int win2k_install_hack =3D 0; > -int rtc_td_hack =3D 0; > +int rtc_driftfix =3D QEMU_RTC_DRIFTFIX_NONE; > int usb_enabled =3D 0; > int singlestep =3D 0; > int smp_cpus =3D 1; > @@ -418,6 +418,9 @@ static void configure_rtc_date_offset(const char *sta= rtdate, int legacy) > static void configure_rtc(QemuOpts *opts) > { > const char *value; > + QEMUClock *clocks[] =3D { host_clock, vm_clock }; > + verify_true(ARRAY_SIZE(clocks) =3D=3D QEMU_RTC_CLOCK_LAST); This and the other verify_true() usage are generating the following build error for me when debug is enabled: cc1: warnings being treated as errors /home/lcapitulino/src/qmp-unstable/vl.c: In function =E2=80=98configure_rtc= =E2=80=99: /home/lcapitulino/src/qmp-unstable/vl.c:422: error: statement with no effect /home/lcapitulino/src/qmp-unstable/vl.c: In function =E2=80=98drive_init=E2= =80=99: /home/lcapitulino/src/qmp-unstable/vl.c:847: error: statement with no effect make[1]: *** [vl.o] Error 1 make: *** [subdir-libhw64] Error 2 > + int clock; > =20 > value =3D qemu_opt_get(opts, "base"); > if (value) { > @@ -429,28 +432,11 @@ static void configure_rtc(QemuOpts *opts) > configure_rtc_date_offset(value, 0); > } > } > - value =3D qemu_opt_get(opts, "clock"); > - if (value) { > - if (!strcmp(value, "host")) { > - rtc_clock =3D host_clock; > - } else if (!strcmp(value, "vm")) { > - rtc_clock =3D vm_clock; > - } else { > - fprintf(stderr, "qemu: invalid option value '%s'\n", value); > - exit(1); > - } > - } > - value =3D qemu_opt_get(opts, "driftfix"); > - if (value) { > - if (!strcmp(value, "slew")) { > - rtc_td_hack =3D 1; > - } else if (!strcmp(value, "none")) { > - rtc_td_hack =3D 0; > - } else { > - fprintf(stderr, "qemu: invalid option value '%s'\n", value); > - exit(1); > - } > - } > + > + clock =3D qemu_opt_get_enum(opts, "clock", QEMU_RTC_CLOCK_HOST); > + rtc_clock =3D clocks[clock]; > + > + rtc_driftfix =3D qemu_opt_get_enum(opts, "driftfix", QEMU_RTC_DRIFTF= IX_NONE); > } > =20 > /***********************************************************/ > @@ -3149,7 +3135,7 @@ int main(int argc, char **argv, char **envp) > win2k_install_hack =3D 1; > break; > case QEMU_OPTION_rtc_td_hack: > - rtc_td_hack =3D 1; > + rtc_driftfix =3D QEMU_RTC_DRIFTFIX_SLEW; > break; > case QEMU_OPTION_acpitable: > do_acpitable_option(optarg);