From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhzLM-0008FL-4w for qemu-devel@nongnu.org; Tue, 14 Apr 2015 07:49:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YhzLJ-0001aK-Cb for qemu-devel@nongnu.org; Tue, 14 Apr 2015 07:49:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhzLJ-0001a6-5F for qemu-devel@nongnu.org; Tue, 14 Apr 2015 07:49:25 -0400 Date: Tue, 14 Apr 2015 13:49:19 +0200 From: Igor Mammedov Message-ID: <20150414134919.4f084e2d@nial.brq.redhat.com> In-Reply-To: <1428696149-12461-1-git-send-email-ehabkost@redhat.com> References: <1428696149-12461-1-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4] target-i386: Register QOM properties for feature flags List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: Paolo Bonzini , Jiri Denemark , qemu-devel@nongnu.org, Andreas =?UTF-8?B?RsOkcmJlcg==?= On Fri, 10 Apr 2015 17:02:29 -0300 Eduardo Habkost wrote: > This uses the feature name arrays to register QOM properties for feature > flags. This simply adds properties that can be configured using -global, > but doesn't change x86_cpu_parse_featurestr() to use them yet. > > Signed-off-by: Eduardo Habkost > --- > Changes v1 -> v2: > * Use "cpuid-" prefix instead of "feat-" > * Register release function for property > * Convert '_' to '-' on feature name before registering property > * Add dev->realized check to property setter > > Changes v2 -> v3: > * Register alias properties for feature name aliases > * Patch is based on x86 tree, at: > https://github.com/ehabkost/qemu.git x86 > > Changes v3 -> v4: > * Remove "cpuid-" prefix altogether > --- > target-i386/cpu.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 115 insertions(+) > > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index e657f10..1d97656 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -2848,12 +2848,120 @@ out: > } > } > > +typedef struct FeatureProperty { > + FeatureWord word; > + uint32_t mask; > +} FeatureProperty; > + > +static void x86_cpu_get_feature_prop(Object *obj, > + struct Visitor *v, > + void *opaque, > + const char *name, > + Error **errp) > +{ > + X86CPU *cpu = X86_CPU(obj); > + CPUX86State *env = &cpu->env; > + FeatureProperty *fp = opaque; > + bool value = (env->features[fp->word] & fp->mask) == fp->mask; maybe s/env->features[fp->word]/*fp->feature_word_ptr/ it would consolidate possible out of bound error place to 1 instead of several as it's now. Also it makes it easier to read for me :). > + visit_type_bool(v, &value, name, errp); > +} > + > +static void x86_cpu_set_feature_prop(Object *obj, > + struct Visitor *v, > + void *opaque, > + const char *name, > + Error **errp) > +{ > + X86CPU *cpu = X86_CPU(obj); > + DeviceState *dev = DEVICE(obj); > + CPUX86State *env = &cpu->env; > + FeatureProperty *fp = opaque; > + bool value; > + > + if (dev->realized) { > + qdev_prop_set_after_realize(dev, name, errp); > + return; > + } > + > + visit_type_bool(v, &value, name, errp); should check error here and return in case of it's set, + local_err + error_propagate() > + if (value) { > + env->features[fp->word] |= fp->mask; > + } else { > + env->features[fp->word] &= ~fp->mask; > + } > +} > + > +static void x86_cpu_release_feature_prop(Object *obj, const char *name, > + void *opaque) > +{ > + FeatureProperty *prop = opaque; > + g_free(prop); > +} > + > +/* Register a boolean feature-bits property. > + * If mask has multiple bits, all must be set for the property to return true. > + * The same property name can be registered multiple times to make it affect > + * multiple bits in the same FeatureWord. > + */ > +static void x86_cpu_register_feature_prop(X86CPU *cpu, > + const char *prop_name, > + FeatureWord w, > + uint32_t mask) isn't used as mask by caller, s/mask/bit/ ??? > +{ > + FeatureProperty *fp; > + ObjectProperty *op; white line here? > + op = object_property_find(OBJECT(cpu), prop_name, NULL); > + if (op) { > + fp = op->opaque; > + assert(fp->word == w); > + fp->mask |= mask; > + } else { > + fp = g_new0(FeatureProperty, 1); > + fp->word = w; > + fp->mask = mask; > + object_property_add(OBJECT(cpu), prop_name, "bool", > + x86_cpu_get_feature_prop, > + x86_cpu_set_feature_prop, > + x86_cpu_release_feature_prop, fp, &error_abort); > + } > +} > + > +static void x86_cpu_register_feature_bit_props(X86CPU *cpu, this adds 1 property and possibly aliases, _props() is confusing here. I'd rename it to x86_cpu_add_feature_bit_prop() and inline above x86_cpu_register_feature_prop() since it's not going to be reused > + FeatureWord w, > + int bit) > +{ > + Object *obj = OBJECT(cpu); > + int i; > + char **names; > + FeatureWordInfo *fi = &feature_word_info[w]; > + > + if (!fi->feat_names) { > + return; > + } > + if (!fi->feat_names[bit]) { > + return; > + } > + > + names = g_strsplit(fi->feat_names[bit], "|", 0); > + > + feat2prop(names[0]); > + x86_cpu_register_feature_prop(cpu, names[0], w, (1UL << bit)); > + > + for (i = 1; names[i]; i++) { > + feat2prop(names[i]); > + object_property_add_alias(obj, names[i], obj, names[0], &error_abort); > + } > + > + g_strfreev(names); > +} > + > static void x86_cpu_initfn(Object *obj) > { > CPUState *cs = CPU(obj); > X86CPU *cpu = X86_CPU(obj); > X86CPUClass *xcc = X86_CPU_GET_CLASS(obj); > CPUX86State *env = &cpu->env; > + FeatureWord w; > static int inited; > > cs->env_ptr = env; > @@ -2894,6 +3002,13 @@ static void x86_cpu_initfn(Object *obj) > cpu->apic_id = -1; > #endif > > + for (w = 0; w < FEATURE_WORDS; w++) { > + int bit; white line here? > + for (bit = 0; bit < 32; bit++) { > + x86_cpu_register_feature_bit_props(cpu, w, bit); > + } > + } > + > x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort); > > /* init various static tables used in TCG mode */